Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S4143: AD0001 NullReferenceException #2235

Closed
Evangelink opened this issue Jan 14, 2019 · 2 comments
Closed

Fix S4143: AD0001 NullReferenceException #2235

Evangelink opened this issue Jan 14, 2019 · 2 comments
Assignees
Labels
Area: VB.NET VB.NET rules related issues. Type: Bug Exceptions and blocking issues during analysis.
Milestone

Comments

@Evangelink
Copy link
Contributor

Description

The rule DotNotOverwriteCollectionElements fails with NRE.

StackTrace is:

Warning	AD0001	Analyzer 'SonarAnalyzer.Rules.VisualBasic.DoNotOverwriteCollectionElements' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.	ConsoleApp1		1	Active	Analyzer 'SonarAnalyzer.Rules.VisualBasic.DoNotOverwriteCollectionElements' threw the following exception:
'Exception occurred with following context:
Compilation: ConsoleApp1
SyntaxTree: C:\Users\Amaury Leve\Source\Repos\ConsoleApp6\ConsoleApp1\Module1.vb
SyntaxNode: C [ExpressionStatementSyntax]@[65..66) (8,0)-(8,1)

System.NullReferenceException: Object reference not set to an instance of an object.
   at SonarAnalyzer.Rules.VisualBasic.DoNotOverwriteCollectionElements.GetFirstArgumentExpression(InvocationExpressionSyntax invocation)
   at SonarAnalyzer.Rules.VisualBasic.DoNotOverwriteCollectionElements.GetIndexOrKey(StatementSyntax statement)
   at SonarAnalyzer.Rules.DoNotOverwriteCollectionElementsBase`1.AnalysisAction(SyntaxNodeAnalysisContext context)
   at SonarAnalyzer.Helpers.DiagnosticAnalyzerContextHelper.<>c__DisplayClass0_0`1.<RegisterSyntaxNodeActionInNonGenerated>b__0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.SonarAnalysisContext.<>c__DisplayClass21_0`1.<RegisterContextAction>b__0(TContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__44`1.<ExecuteSyntaxNodeAction>b__44_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)

Repro steps

Module Module1

    Sub Main()
        Dim f1 = New Foo
        Dim f2 = New Foo

        f1.Attributes.Item("Title") = "some text goes here"
        f2.Attributes.Item("Title") = "some other text goes here"
    End Sub

End Module

Class Foo
    Public Attributes As Dictionary(Of String, String)
End Class

Related information

  • SonarAnalyzer.VisualBasic 7.10
@Evangelink
Copy link
Contributor Author

@valhristov Could you try and tell me if you can reproduce the issue? I added the snippet into the unit test class and I haven't had any failure.

@valhristov
Copy link
Contributor

Yes, I can:

Module NullReferenceReproducer
    Sub Main()
        Bar ' AD0001 NullReferenceException in GetFirstArgumentExpression
    End Sub

    Public Sub Bar()
    End Sub
End Module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: VB.NET VB.NET rules related issues. Type: Bug Exceptions and blocking issues during analysis.
Projects
None yet
Development

No branches or pull requests

2 participants