System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensions.cs Set methods throw different exception
In issue dotnet/corefx#15375, @JonHanna recommended submitting an issue to make the exceptions being thrown be consistent. I would like to do this work if this can be assigned to me. Thanks, Michael
Yes, these all seem like they should throw ArgumentNullException rather than NullReferenceException. Is there too big a compat issue to add explicit validation that would do so?
(If there is such a compat issue, it would be worth a check to make sure nothing is left half-done before the NRE is thrown).
In general: Changing exceptions might be a breaking change. It is also divergence between platforms (.NET Core vs. Desktop vs. Xamarin). So the key question is: How is the change helping developers? What's the value? Note: The value should be non-trivial to overweight the risk (which is non-zero).
cc: @JeremyKuhne @ianhays for providing IO specific point of view.
@karelz general guidance is good, but I think it's worth having a discussion about NullReference versus ArgumentNull in general as it is a bit different than changing exceptions thrown by argument validation.
I lean towards adding ArgumentNull when we get a null argument that causes a NullRef. NullRef infers accidental rather than intentional (certainly moreso than ArgumentNull). It can potentially make exception tracking a bit more difficult. (Thinking of first chance exceptions while debugging.)
If we don't have a null arg and/or we decide not to change I'd argue that we should always explicitly throw NullRef to reduce the risk of introducing corrupted state / breaking compat.
@KrzysztofCwalina, @terrajobst, what is your opinion on this particular case? (Adding an ArgumentNull instead of letting things fall over at NullReference.)
We recently addressed this by making sure both the .NET Core and the .NET Framework versions of FileSystemAclExtensions threw ArgumentNullException if the this argument was null. See history for those two files:
https://github.com/dotnet/runtime/blob/master/src/libraries/System.IO.FileSystem.AccessControl/src/System/IO/FileSystemAclExtensions.cs https://github.com/dotnet/runtime/blob/master/src/libraries/System.IO.FileSystem.AccessControl/src/System/IO/FileSystemAclExtensions.net46.cs
Should be fixed in 5.0. Closing per @carlossanlop comment above. https://github.com/dotnet/corefx/issues/15589#issuecomment-575759695