-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Port nullability annotations to System.Xml.ReaderWriter contract #41083
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
Conversation
Should this return Refers to: src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs:1073 in a2a0ead. [](commit_id = a2a0ead2ac98db85b3d8bcb5de769dafdc7ca897, deletion_comment = False) |
Should Refers to: src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs:825 in a2a0ead. [](commit_id = a2a0ead2ac98db85b3d8bcb5de769dafdc7ca897, deletion_comment = False) |
How come this overload has Refers to: src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs:1249 in a2a0ead. [](commit_id = a2a0ead2ac98db85b3d8bcb5de769dafdc7ca897, deletion_comment = False) |
src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs
Outdated
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.
As per documentation:
If the attribute replaces an existing attribute with the same name, the old XmlAttribute is returned; otherwise, null is returned.
| public virtual System.Xml.XmlAttribute SetAttributeNode(System.Xml.XmlAttribute newAttr) { throw null; } | |
| public virtual System.Xml.XmlAttribute? SetAttributeNode(System.Xml.XmlAttribute newAttr) { throw null; } |
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.
I don't believe this actually returns null - looking at the implementation it returns old node if it already exists and new node if it doesn't
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.
I changed it because is virtual and someone could override it to return null; looking at "find all references" in VS, we don't even dereference the method's return value so it doesn't really affect libraries code if the method returns null or not.
If you feels like is pointless to make it nullable I can undo this change.
…ommon Xml related annotations
| public virtual System.Xml.XmlText CreateTextNode(string? text) { throw null; } | ||
| public virtual System.Xml.XmlWhitespace CreateWhitespace(string? text) { throw null; } | ||
| public virtual System.Xml.XmlDeclaration CreateXmlDeclaration(string version, string? encoding, string? standalone) { throw null; } | ||
| public virtual System.Xml.XmlElement? GetElementById(string elementId) { throw null; } | ||
| public virtual System.Xml.XmlNodeList GetElementsByTagName(string name) { throw null; } | ||
| public virtual System.Xml.XmlNodeList GetElementsByTagName(string localName, string namespaceURI) { throw null; } |
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.
string namespaceURI is correct here as it will throw but I think this is incidental and due to bug in the code, I think we should ideally fix the bug and change annotation (not in this PR)
| [System.Diagnostics.DebuggerStepThroughAttribute] | ||
| public virtual System.Threading.Tasks.Task<object> ReadContentAsAsync(System.Type returnType, System.Xml.IXmlNamespaceResolver namespaceResolver) { throw null; } | ||
| public virtual System.Threading.Tasks.Task<object> ReadContentAsAsync(System.Type returnType, System.Xml.IXmlNamespaceResolver? namespaceResolver) { throw null; } |
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.
Most likely couple of namespaceResolvers below should be nullable, i.e.:
ReadElementContentAs, ReadElementContentAsAsync
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.
Seems it will throw InvalidOperationException in some cases when this is null
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.
Yes, that's why I didn't change those signatures on #41079
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
I think this will always return false if you pass null. In all other places null implies |
You're right. I looked at the implementation and this appears broken to me. We should leave it as you have it now, and I opened #41461 for us to consider to make it nullable in the future. |
Contributes to #2339