-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Nullability annotations for System.Data #38810
Conversation
2aa2c47
to
1d6d1d2
Compare
src/libraries/System.Data.Common/src/System/Data/Common/AdapterUtil.Common.cs
Show resolved
Hide resolved
@@ -445,12 +446,12 @@ public void Clear() | |||
try | |||
{ | |||
// this will smartly add and remove the appropriate tables. | |||
BaseGroupSwitch(constraints, oldLength, null, 0); | |||
BaseGroupSwitch(constraints, oldLength, Array.Empty<Constraint>(), 0); |
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 following 0 count means the array never gets enumerated anyway
src/libraries/System.Data.Common/src/System/Data/Common/BooleanStorage.cs
Show resolved
Hide resolved
src/libraries/Common/src/System/Data/Common/DbConnectionOptions.Common.cs
Show resolved
Hide resolved
[System.ComponentModel.DefaultValueAttribute("")] | ||
[System.Diagnostics.CodeAnalysis.AllowNull] | ||
public virtual string QuotePrefix { get { throw null; } set { } } |
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 see call sites for some of these virtuals checking for and allowing null. Is non-nullable correct for the return value for all of these?
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 default implementation coalesces to string.Empty, and it's supposed to be a string you can always concatenate before/after the string. It's true that it's virtual so anything's possible, though I'm only seeing IsNullOrEmpty in the Odbc and OleDb providers, and SqlClient just calls base.QuotePrefix.
Where are you seeing null checks, anything persuasive? I can make it nullable if you think that's safer.
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.
Where are you seeing null checks
The IsNullOrEmpty checks you mentioned. But it's not just in Odbc and OleDb, e.g. DBCommandBuilder allows null in both private void BuildInformation(DataTable schemaTable)
and private string QuotedColumn(string column)
.
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.
OK, yeah - I see them though they're also IsNullOrEmpty. I think the point is to check for length 0 rather than for null (the coalescing behavior of the property getters is a good indication), but if you think we should annotate these as nullable I can do that. We could also do a more thorough search outside the BCL to see who's overriding DbCommandBuilder and what they're doing, let me know.
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 only spot checked and I'm exhausted; thanks for slogging through this.
2daaa57
to
655d26b
Compare
Tagging subscribers to this area: @roji, @ajcvickers |
8aed39b
to
dc8fe20
Compare
Following ec73c56. A few corners have been left annotated because of dependencies.
dc8fe20
to
d0f5d5e
Compare
@stephentoub have merged this to be able to continue working on Odbc etc., thanks for taking the time to review this (it was most definitely a slog). If there are any outstanding points (e.g. #38810 (comment)) let me know and I'll do fix-up to this in a later PR. |
Following ec73c56.
Part of #2339