- Notifications
You must be signed in to change notification settings - Fork5.1k
Remove usage of !! from dotnet/runtime#68178
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
GrabYourPitchforks commentedApr 18, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Review based on acd12317c3d8d1b54ffd14a8a6624be8ab35059d
|
GrabYourPitchforks commentedApr 18, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The GitHub UI is misbehaving trying to leave feedback within the PR. But inClaimsIdentity.cs andClaimsPrincipal.cs: the 6.0 behavior is that for iterators, theArgumentNullException is thrown lazily, where in 7.0 it's thrown eagerly. I believe your 7.0 behavior is correct but wanted to surface it as a potential breaking change and make sure we were ok with it. |
....Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ChainPal.Windows.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
stephentoub commentedApr 19, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks, yes, I should have mentioned that. In going through and manually reviewing every iterator and async method that had |
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.
159 / 1412 files viewed
I will continue tomorrow.
src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/Microsoft.Extensions.Configuration.Xml/src/XmlConfigurationElementTextContent.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/Microsoft.Extensions.DependencyInjection/src/DefaultServiceProviderFactory.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/ConstantCallSite.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Just wondering, how did you undo the changes, it's a lot of changes and a large code base
And if you did more than 1,2 how did you decide on that method? |
stephentoub commentedApr 19, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Revert wasn't ideal because:
My process:
|
Thank you for the detailed answer. |
I'll assume the downvotes are about C# 11 removing the |
SteveDunn commentedApr 19, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've taken a look through a couple of files. One thing that has struck me is how nice it'd be if we could shorten (yes, I recognise the irony!) the null checking code, e.g, instead of: ArgumentNullException.ThrowIfNull(element);ArgumentNullException.ThrowIfNull(attributeType); we could have ... ArgumentNullException.ThrowIfNull(element,attributeType); I think this'd work if we added overloads, e.g.: publicstaticvoidThrowIfNull([NotNull]object?argument1,[NotNull]object?argument2,[CallerArgumentExpression("argument1")]string?paramName1=null,[CallerArgumentExpression("argument2")]string?paramName2=null){if(argument1isnull){Throw(paramName1);}if(argument2isnull){Throw(paramName2);}} We could have up to 5 parameters for normal software (and maybe a special 'Enterprise' version for Finance sector developers, with up to 30 parameters! ;) ) |
Actually, forget my idea above;I implemented it, but method overload resolution means itlikely will call the wrong overload. Examples in the PR. |
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.
600 / 1416 files viewed. To be continued as soon as possible.
I found we're down to about 70 occurrences of an assignment with?? throw new ArgumentNullException(nameof(...
. If we want to eliminate that pattern, we could do so in a follow-up PR pretty quickly, but I don't know if that was the aim or not.
src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/Microsoft.Extensions.Hosting/src/Internal/ServiceFactoryAdapter.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Collections.NonGeneric/src/System/Collections/Queue.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...s/System.ComponentModel.Primitives/src/System/ComponentModel/InvalidEnumArgumentException.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Composition.Runtime/src/System/Composition/Runtime/Util/Formatters.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/ContractUtils.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
My goal wasn't to remove them, but rather if a project already had a ThrowHelper, to use it consistently. |
Thanks for trying that out,@SteveDunn. The idea was intriguing. |
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 left one comment that calls out a subtle change in logic that we might want to back out for caution. Several other comments around code comments. And a couple formatting fixes/suggestions.
@stephentoub - your devotion to this was admirable. This was a major undertaking in both directions! And even though!!
got removed, your pair of PRs around null argument handling resulted in better consistency as well as mitigations to some lurking NullReferenceException possibilities.
Thank you for the effort that went into this and for teaching me a few things during the review.
...ibraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/InterpretedFrame.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.Xml/src/System/Xml/Core/ReadContentAsBinaryHelperAsync.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Private.Xml/src/System/Xml/Core/XmlCharCheckingReaderAsync.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...dContext/src/System/Reflection/TypeLoading/Assemblies/Ecma/EcmaAssembly.ManifestResources.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ObjectSecurity.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
- Use ArgumentNullException.ThrowIfNull instead where possible. It's only usable for projects that only target .NET 6+, and it can't be used in places like this(...) or base(...).- In other cases, if the project already has a ThrowHelper, augment it for null as needed and use that.- For most of the extensions projects, add a ThrowHelper.ThrowIfNull that replicates ArgumentNullException.ThrowIfNull.- For everything else, just use "throw new".
Thanks,@GrabYourPitchforks and@jeffhandley, for reviewing. |
React to:
https://devblogs.microsoft.com/dotnet/csharp-11-preview-updates/#remove-parameter-null-checking-from-c-11
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-13.md#c-language-design-meeting-for-april-11th-2022