I can call it with a null value, like this: var gotTen = IsTen(null);
I expected SonarLint to complain about the “value.Value” access, in the IsTen function, but it doesn’t.
Tried in a separate project too, just to check nobody disabled the rule by mistake.
Is this a bug? If not, please consider it a feature request.
Sorry, it seems I missed the report guide somehow…
The rule is S3655: Empty nullable value should not be accessed
Also, SonarLint will complain as soon as the commented out line is enabled:
Hi @mBardos76, and a happy new year!
We currently consider this example to be compliant. We do not make assumptions about the state of a nullable value type unless the code checks explicitly for null. The reasoning is that the developer might know that this method never gets passed a null argument, and maybe they cannot change the method signature for some reason.
However, I see value in raising here and will discuss changing the rule’s behavior with the team.
Maybe also of interest to you: While investigating this issue, I found that we have a similar situation with nullable reference types. If nullable context is enabled, the arguments for treating this as Noncompliant become much more substantial.