dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.07k stars 4.04k forks source link

PropertiesShouldNotBeWriteOnlyAnalyzer threw an exception of type 'System.NullReferenceException' #33240

Open davkean opened 5 years ago

davkean commented 5 years ago
        protected override ImmutableDictionary<string, string> GetMap => s_getOutputTypeExMap;
        protected override ImmutableDictionary<string, string> SetMap => s_setOutputTypeExMap;
Severity    Code    Description Project File    Line    Category    Suppression State   Detail Description
Error   AD0001  Analyzer 'Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.PropertiesShouldNotBeWriteOnlyAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.  Microsoft.VisualStudio.ProjectSystem.Managed.VS     1   Compiler    Active  Analyzer 'Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.PropertiesShouldNotBeWriteOnlyAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: Microsoft.VisualStudio.ProjectSystem.Managed.VS
ISymbol: GetMap (Property)

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.Symbols.MemberSignatureComparer.HaveSameReturnTypes(Symbol member1, TypeMap typeMap1, Symbol member2, TypeMap typeMap2, TypeCompareKind typeComparison)
   at Microsoft.CodeAnalysis.CSharp.Symbols.MemberSignatureComparer.Equals(Symbol member1, Symbol member2)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.IsInterfaceMemberImplementation(Symbol candidateMember, Symbol interfaceMember, Boolean implementingTypeIsFromSomeCompilation)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindPotentialImplicitImplementationMemberDeclaredInType(Symbol interfaceMember, Boolean implementingTypeIsFromSomeCompilation, TypeSymbol currType, Symbol& implicitImpl, Symbol& closeMismatch)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.ComputeImplementationForInterfaceMember(Symbol interfaceMember, TypeSymbol implementingType, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.ComputeImplementationAndDiagnosticsForInterfaceMember(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindImplementationForInterfaceMemberWithDiagnostics(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindImplementationForInterfaceMember(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.Microsoft.CodeAnalysis.ITypeSymbol.FindImplementationForInterfaceMember(ISymbol interfaceMember)
   at Analyzer.Utilities.Extensions.ISymbolExtensions.IsImplementationOfAnyImplicitInterfaceMember[TSymbol](ISymbol symbol)
   at Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.PropertiesShouldNotBeWriteOnlyAnalyzer.AnalyzeSymbol(SymbolAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSymbolActionsCore>b__40_1(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
mavasani commented 5 years ago

Seems to be a Roslyn bug - the analyzer is invoking a public API, which seems to cause an NRE deep inside Microsoft.CodeAnalysis.CSharp.Symbols.MemberSignatureComparer.HaveSameReturnTypes

mavasani commented 5 years ago

Tagging @jmarolf , who also seemed to have hit this previously. Jon, did you file a Roslyn bug for it?

davkean commented 5 years ago

Ran into this again, this time SetMap:

Severity    Code    Description Project File    Line    Category    Suppression State   Detail Description
Error   AD0001  Analyzer 'Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.PropertiesShouldNotBeWriteOnlyAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.  Microsoft.VisualStudio.ProjectSystem.Managed.VS     1   Compiler    Active  Analyzer 'Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.PropertiesShouldNotBeWriteOnlyAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: Microsoft.VisualStudio.ProjectSystem.Managed.VS
ISymbol: SetMap (Property)

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.Symbols.MemberSignatureComparer.HaveSameReturnTypes(Symbol member1, TypeMap typeMap1, Symbol member2, TypeMap typeMap2, TypeCompareKind typeComparison)
   at Microsoft.CodeAnalysis.CSharp.Symbols.MemberSignatureComparer.Equals(Symbol member1, Symbol member2)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.IsInterfaceMemberImplementation(Symbol candidateMember, Symbol interfaceMember, Boolean implementingTypeIsFromSomeCompilation)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindPotentialImplicitImplementationMemberDeclaredInType(Symbol interfaceMember, Boolean implementingTypeIsFromSomeCompilation, TypeSymbol currType, Symbol& implicitImpl, Symbol& closeMismatch)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.ComputeImplementationForInterfaceMember(Symbol interfaceMember, TypeSymbol implementingType, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.ComputeImplementationAndDiagnosticsForInterfaceMember(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindImplementationForInterfaceMemberWithDiagnostics(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindImplementationForInterfaceMember(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.Microsoft.CodeAnalysis.ITypeSymbol.FindImplementationForInterfaceMember(ISymbol interfaceMember)
   at Analyzer.Utilities.Extensions.ISymbolExtensions.IsImplementationOfAnyImplicitInterfaceMember[TSymbol](ISymbol symbol)
   at Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.PropertiesShouldNotBeWriteOnlyAnalyzer.AnalyzeSymbol(SymbolAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSymbolActionsCore>b__40_1(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
mavasani commented 5 years ago

This needs to be ported to Roslyn repo. @jinujoseph do you have permissions to port issues from here to that repo?

davkean commented 5 years ago

Done.

jasonmalinowski commented 5 years ago

I hit this today while dogfooding:

Severity    Code    Description Project File    Line    Suppression State   Detail Description
Error   AD0001  Analyzer 'Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.CancellationTokenParametersMustComeLastAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. Microsoft.CodeAnalysis.CSharp.Workspaces        1   Active  Analyzer 'Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.CancellationTokenParametersMustComeLastAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: Microsoft.CodeAnalysis.CSharp.Workspaces
ISymbol: .ctor (Method)

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.CodeAnalysis.CSharp.Symbols.MemberSignatureComparer.HaveSameReturnTypes(Symbol member1, TypeMap typeMap1, Symbol member2, TypeMap typeMap2, TypeCompareKind typeComparison)
   at Microsoft.CodeAnalysis.CSharp.Symbols.MemberSignatureComparer.Equals(Symbol member1, Symbol member2)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.IsInterfaceMemberImplementation(Symbol candidateMember, Symbol interfaceMember, Boolean implementingTypeIsFromSomeCompilation)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindPotentialImplicitImplementationMemberDeclaredInType(Symbol interfaceMember, Boolean implementingTypeIsFromSomeCompilation, TypeSymbol currType, Symbol& implicitImpl, Symbol& closeMismatch)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.ComputeImplementationForInterfaceMember(Symbol interfaceMember, TypeSymbol implementingType, DiagnosticBag diagnostics)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.ComputeImplementationAndDiagnosticsForInterfaceMember(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindImplementationForInterfaceMemberInNonInterfaceWithDiagnostics(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.FindImplementationForInterfaceMember(Symbol interfaceMember)
   at Microsoft.CodeAnalysis.CSharp.Symbols.TypeSymbol.Microsoft.CodeAnalysis.ITypeSymbol.FindImplementationForInterfaceMember(ISymbol interfaceMember)
   at Analyzer.Utilities.Extensions.ISymbolExtensions.IsImplementationOfAnyImplicitInterfaceMember[TSymbol](ISymbol symbol)
   at Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.CancellationTokenParametersMustComeLastAnalyzer.<>c__DisplayClass6_0.<Initialize>b__1(SymbolAnalysisContext symbolContext)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c.<ExecuteSymbolActionsCore>b__40_1(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.

Different analyzer, but same API being busted. @jcouv or @agocke this one on your radar?

mavasani commented 5 years ago

Another instance of the same NRE: https://github.com/dotnet/roslyn-analyzers/issues/2659

mavasani commented 5 years ago

Another report of the same NRE: https://github.com/dotnet/roslyn-analyzers/issues/2694 from @jnm2

@gafter @jcouv @agocke

jnm2 commented 5 years ago

I hit this again via Microsoft.VisualStudio.Threading.Analyzers.VSTHRD102AvoidJtfRunInNonPublicMembersAnalyzer

jnm2 commented 5 years ago

...and again via Microsoft.NetCore.Analyzers.Data.ReviewSqlQueriesForSecurityVulnerabilities