You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I get a NullReferenceException trying to get DefaultConfiguration because it is null. However, the type of DefaultConfiguration is ReportingConfiguration, and that has a default value of "warning".
The Problem
There's two issues that as a user I find surprising:
The APIs don't have nullability annotations, so the compiler doesn't warn that I may get a null from the property
I now need to manually construct "default" or "fallback" objects in my own usage
The Workaround
I can do a workaround in my own code like this to avoid the issue:
The request is for this "default object if null" pattern to be part of the API to avoid repeating it everywhere or creating extension methods for multiple properties. If that's not possible / not desirable, then an extension like the above is acceptable if nullability annotations are also possible to make it clear where default values may be needed.
The text was updated successfully, but these errors were encountered:
I just hit this issue with the
ReportingDescriptor
object, but it likely applies to other objects as well.The Scenario
Consider a Sarif v2.1 log like this:
If I try to get the default configuration level like this:
I get a
NullReferenceException
trying to getDefaultConfiguration
because it isnull
. However, the type of DefaultConfiguration isReportingConfiguration
, and that has a default value of "warning".The Problem
There's two issues that as a user I find surprising:
The Workaround
I can do a workaround in my own code like this to avoid the issue:
or more generically I can write an extension like this:
The Solution
The request is for this "default object if null" pattern to be part of the API to avoid repeating it everywhere or creating extension methods for multiple properties. If that's not possible / not desirable, then an extension like the above is acceptable if nullability annotations are also possible to make it clear where default values may be needed.
The text was updated successfully, but these errors were encountered: