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 S3881: Rule should not fail with 'Syntax node is not within syntax tree' #690

Closed
jcurl opened this issue Aug 12, 2017 · 1 comment
Closed
Assignees
Labels
Type: Bug Exceptions and blocking issues during analysis.
Milestone

Comments

@jcurl
Copy link

jcurl commented Aug 12, 2017

Description

The following warning is generated for a particular class

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Warning	AD0001	Analyzer 'SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly' threw an exception of type 'System.ArgumentException' with message 'Syntax node is not within syntax tree'.	TestTraceListener		1	Active	Analyzer 'SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly' threw the following exception:
'Exception occurred with following context:
Compilation: HBAS.Automation.TestTraceListener
SyntaxTree: C:\Users\jcurl\Documents\Programming\helios.base\framework\testtracelistener\code\TestCase.MappingCollection.cs
SyntaxNode: public partial class TestCase { ... [ClassDeclarationSyntax]@[142..6895) (7,4)-(147,5)

System.ArgumentException: Syntax node is not within syntax tree
   at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.CheckSyntaxNode(CSharpSyntaxNode syntax)
   at Microsoft.CodeAnalysis.CSharp.SyntaxTreeSemanticModel.GetDeclaredMemberSymbol(CSharpSyntaxNode declarationSyntax)
   at Microsoft.CodeAnalysis.CSharp.SyntaxTreeSemanticModel.GetDeclaredSymbol(BaseMethodDeclarationSyntax declarationSyntax, CancellationToken cancellationToken)
   at SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly.DisposableChecker.VerifyDispose(MethodDeclarationSyntax disposeMethod, Boolean isSealedClass)
   at SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly.DisposableChecker.GetIssueLocations()
   at SonarAnalyzer.Rules.CSharp.ImplementIDisposableCorrectly.<>c.<Initialize>b__6_0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.DiagnosticAnalyzerContextHelper.<>c__DisplayClass0_0`1.<RegisterSyntaxNodeActionInNonGenerated>b__0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.SonarAnalysisContext.<>c__DisplayClass12_0`1.<RegisterSyntaxNodeAction>b__0(SyntaxNodeAnalysisContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass42_1`1.<ExecuteSyntaxNodeAction>b__1()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info)
-----
'.

Repro steps

Please see attached a copy of the two source files that appear to be relevant.
TestCaseMapping.zip

Expected behavior

No AD0001 should be raised.

Actual behavior

See problem description. AD0001 is unexpectedly raised

Known workarounds

None known

Related information

  • SonarC# Version: 3.4.0.1732
  • Visual Studio Version VS2015 U3 Enterprise
@Evangelink Evangelink added Area: Rules Type: Bug Exceptions and blocking issues during analysis. labels Aug 15, 2017
@Evangelink Evangelink added this to the 6.4 milestone Aug 15, 2017
@Evangelink
Copy link
Contributor

Hi @jcurl,
Thanks for this bug report! We will deal with it in the next version of SonarC#.

@Evangelink Evangelink changed the title AD0001: Analyser error Fix S3881: Rule should not fail with 'Syntax node is not within syntax tree' Aug 15, 2017
@Evangelink Evangelink self-assigned this Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Exceptions and blocking issues during analysis.
Projects
None yet
Development

No branches or pull requests

2 participants