-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Enable Nullability in multiple Design
classes
#8390
Enable Nullability in multiple Design
classes
#8390
Conversation
ImageListImageEditor
Design
classes
b9ce87b
to
136f84e
Compare
src/System.Windows.Forms.Design/src/System/Drawing/Design/ImageEditor.cs
Show resolved
Hide resolved
@lonitra I think the test failures are unrelated? |
@@ -48,12 +46,12 @@ protected static string CreateExtensionsString(string[] extensions, string sep) | |||
protected static string CreateFilterEntry(IconEditor editor) | |||
{ | |||
string description = editor.GetFileDialogDescription(); | |||
string extensions = CreateExtensionsString(editor.GetExtensions(), ","); | |||
string extensionsWithSemicolons = CreateExtensionsString(editor.GetExtensions(), ";"); | |||
string? extensions = CreateExtensionsString(editor.GetExtensions(), ","); |
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 think there is some inconsistency here. The first parameter in CreateExtensionsString()
is nullable, but it looks like every time CreateExtensionsString()
is called we are passing in the return value of GetExtensions()
which is currently nonnullable. Could you verify whether or not GetExtensions()
ever returns a null
value and adjust accordingly?
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.
GetExtensions
always returns a non-null value. CreateExtensionsString
is protected
so it is externally accessible. So a null value is possible.
I've removed the nullability on CreateExtensionsString
parameter extensions
. I think its best to let the user know that we expect a value. Since if you pass null, we return 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.
There are still checks on line 28. If this were made publicly accessible, what is the benefit to modify the behavior?
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 think I might have been wrong here. In a stricter sense, if we throw a ArguementNullException
or ArguementException
, then it would make more sense to annotate that we don't want nulls. But because we handle it in code, I think we should have the nullability.
I think the idea is that if a null input is going to cause an error or invalid state, then we annotate it not null. This isn't the case here.
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.
Correct, while we like to make it explicit with respect to nullability, in this case, we are handling null values and it's been exposed publicly. We should mark it nullable for compatibility even when we internally never pass null. Our documentation is also doesn't enforce this.
Add null annotations to IconEditor
9f3a608
to
665c32c
Compare
I rebased due to a clash. Apologies for that. The last commit is really the only change. |
Enable Nullability in multiple Design classes
Related: #8342
Microsoft Reviewers: Open in CodeFlow