Closed pavel-mikula-sonarsource closed 2 months ago
The only place where this can happen is this line, if declaration.InputType
is null. Then, the null value ends up in the extension methods where an NRE is thrown.
I couldn't yet replicate it. I tried with using object
, dynamic
or generic types in declaration patterns.
The user shared the code. It looks harmless:
var collectiveEmployee = e.Item.DataItem as CollectiveBaseDto;
...
if (collectiveEmployee is CollectiveEmployeeEpldto CollectiveEPLDTOEmp)
Do you know where the call to .Any
comes from in the stack trace?
In case InputType
is null
, then InputType.DerivesOrImplements
returns false
, because it's null-tolerant everywhere.
I looked again at the stack trace: It is this line:
private static bool Implements(this ITypeSymbol typeSymbol, ISymbol type) =>
typeSymbol is { }
&& typeSymbol.AllInterfaces.Any(x => type.IsDefinition ? x.OriginalDefinition.Equals(type) : x.Equals(type));
It can throw an NRE if type
, x
or x.OriginalDefinition
are null
.
type
is null if declaration.NarrowedType
is null
.x
is null if typeSymbol.AllInterfaces
contains a null reference (probably not possible?).x.OriginalDefinition
be null
?The first one seems the most likely to me, but I'm not sure.
This makes sense.
type
is null ifdeclaration.NarrowedType
isnull
.
AllInterfaces
returns ImmutableArray
that is a struct and cannot be null
OriginalDefinition
cannot be null
, it defaults to this
.
I tried with VSBuild Tools 2019 and 2022. I could not reproduce it.
As reported here and observed inside ascx.cs file:
We don't have a reproducer (yet).