-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Nullable annotations for System.Runtime.Serialization.Xml and System.Runtime.Serialization.Json #41476
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
Nullable annotations for System.Runtime.Serialization.Xml and System.Runtime.Serialization.Json #41476
Conversation
Fix nullable errors in SchemaExporter.
|
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
|
fyi - @HongGit @StephenMolloy - as the owners of this area. |
|
Unrelated to this PR: There is a file that doesn't even compile in System.Private.DataContractSerialization and is a duplicate of the homonymous named file |
...m.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContractResolver.cs
Show resolved
Hide resolved
...m.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContractResolver.cs
Show resolved
Hide resolved
...m.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContractResolver.cs
Show resolved
Hide resolved
...System.Private.DataContractSerialization/src/System/Runtime/Serialization/AccessorBuilder.cs
Show resolved
Hide resolved
...DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerReadContext.cs
Show resolved
Hide resolved
...DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerReadContext.cs
Show resolved
Hide resolved
| } | ||
|
|
||
| internal virtual XmlDictionaryString TopLevelElementName | ||
| internal virtual XmlDictionaryString? TopLevelElementName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[DisallowNull]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does [DisallowNull] work with overrides? This one is a bit tricky because the base class has:
class DataContract
{
XmlDictionaryString _name; // can't be null
public XmlDictionaryString Name { get { } set{ _name = value; } }
public virtual XmlDictionaryString? TopLevelElementName
{
get { return _name; } set{ _name = value; }
}
}but then a derived class does:
class DerivedDataContract : DataContract
{
XmlDictionaryString? _topLevelName ; // can be null
public override XmlDictionaryString? TopLevelElementName
{
get { return _topLevelName ; } set{ _topLevelName = value; }
}
}And when trying to clone the objects, now we have a problem:
Lines 1508 to 1509 in 6072e4d
| clonedHelper.TopLevelElementName = this.TopLevelElementName; | |
| clonedHelper.TopLevelElementNamespace = this.TopLevelElementNamespace; |
The getter can be null, but the setter doesn't allow for it.
...es/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs
Show resolved
Hide resolved
| } | ||
|
|
||
| public override void WriteXmlnsAttribute(string prefix, string ns) | ||
| public override void WriteXmlnsAttribute(string? prefix, string ns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public override void WriteStartAttribute(string prefix, string localName) and overload might be worth filing a bug on NRE or at least TODO-NULLABLE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WriteStartAttribute methods are internal and are never called with null for prefix, so I left them as non-nullable and didn't change the code. But WriteXmlnsAttribute could be called with null, so that's why I fixed it here.
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlConverter.cs
Show resolved
Hide resolved
...es/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs
Show resolved
Hide resolved
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryWriter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryWriter.cs
Outdated
Show resolved
Hide resolved
...rivate.DataContractSerialization/src/System/Runtime/Serialization/XmlSerializableServices.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.Serialization.Xml/ref/System.Runtime.Serialization.Xml.cs
Outdated
Show resolved
Hide resolved
krwq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after fixing/resolving comments
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBinaryReader.cs
Show resolved
Hide resolved
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBinaryWriter.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise; public API annotations LGTM.
|
I believe all current feedback has been addressed. I left a few conversations open with pending questions. Please let me know if you have any more feedback. I'd like to merge this by the EOD. |
Contributes to #2339
cc @jeffhandley @terrajobst