-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert unintentional nullability changes and fix inconsistencies in StringContent ctrs #83423
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsThis is a follow-up on #81506 (comment). We introduced some inconsistencies and unintentional nullability changes in
Since this was an unintentional change, I suggest to revisit it for .NET 8.0, relaxing nullability for all public class StringContent : ByteArrayContent
{
- public StringContent(string content, MediaTypeHeaderValue mediaType);
+ public StringContent(string content, MediaTypeHeaderValue? mediaType);
- public StringContent(string content, Encoding? encoding, string mediaType);
+ public StringContent(string content, Encoding? encoding, string? mediaType);
- public StringContent(string content, Encoding? encoding, MediaTypeHeaderValue mediaType);
+ public StringContent(string content, Encoding? encoding, MediaTypeHeaderValue? mediaType);
}
|
The changes look consistent with the code's treatment of those parameters. public class StringContent : ByteArrayContent
{
- public StringContent(string content, MediaTypeHeaderValue mediaType);
+ public StringContent(string content, MediaTypeHeaderValue? mediaType);
- public StringContent(string content, Encoding? encoding, string mediaType);
+ public StringContent(string content, Encoding? encoding, string? mediaType);
- public StringContent(string content, Encoding? encoding, MediaTypeHeaderValue mediaType);
+ public StringContent(string content, Encoding? encoding, MediaTypeHeaderValue? mediaType);
} |
This is a follow-up on #81506 (comment). We introduced some inconsistencies and unintentional nullability changes in
StringContent
's constructors. Chronologically:mediaType
args to be nullableMediaTypeHeaderValue mediaType
to be non-nullable, which is inconsistent with the then-existing API-s.mediaType
args to be non-nullableMediaTypeHeaderValue mediaType
don't do null-check on that arg, simply allowing the property to be set to nullruntime/src/libraries/System.Net.Http/src/System/Net/Http/StringContent.cs
Line 59 in 58719ec
#81722 provides a minimal fix, however, since this was an unintentional change, I suggest to revisit it for .NET 8.0, relaxing nullability for all
mediaType
declarations, explicitly settingtext/plain
when null is being passed. This should be fairly trivial to implement.The text was updated successfully, but these errors were encountered: