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 S3966: Rule should not throw cast exception #587

Closed
jcurl opened this issue Jul 21, 2017 · 5 comments · Fixed by #592
Closed

Fix S3966: Rule should not throw cast exception #587

jcurl opened this issue Jul 21, 2017 · 5 comments · Fixed by #592
Assignees
Labels
Type: Bug Exceptions and blocking issues during analysis.
Milestone

Comments

@jcurl
Copy link

jcurl commented Jul 21, 2017

Description

The error code AD0001 shows up:

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Warning	AD0001	Analyzer 'SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax'.'.	Datastructures		1	Active	Analyzer 'SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce' threw the following exception:
'Exception occurred with following context:
Compilation: HBAS.Datastructures
SyntaxTree: C:\Users\jcurl\Documents\Programming\HELIOS\helios.base\framework\datastructures\code\Diagnostic\Process.cs
SyntaxNode: private void DisposeWithException ... [MethodDeclarationSyntax]@[30218..30446) (659,8)-(664,9)

System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax'.
   at SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce.ObjectDisposedPointerCheck.VisitInvocationExpression(InvocationExpressionSyntax instruction, ProgramState programState)
   at SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce.ObjectDisposedPointerCheck.PreProcessInstruction(ProgramPoint programPoint, ProgramState programState)
   at SonarAnalyzer.Helpers.FlowAnalysis.CSharp.ExplodedGraph.VisitInstruction(ExplodedGraphNode node)
   at SonarAnalyzer.Helpers.FlowAnalysis.Common.ExplodedGraph.Walk()
   at SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce.CheckForMultipleDispose(ExplodedGraph explodedGraph, SyntaxNodeAnalysisContext context)
   at SonarAnalyzer.Helpers.FlowAnalysis.CSharp.FlowAnalysisExtensions.Analyze(CSharpSyntaxNode declarationBody, ISymbol symbol, Action`2 analyze, SyntaxNodeAnalysisContext context)
   at SonarAnalyzer.Helpers.FlowAnalysis.CSharp.FlowAnalysisExtensions.<>c__DisplayClass0_0.<RegisterExplodedGraphBasedAnalysis>b__1(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

I'm not able to identify the code location in my project that shows the problem. As the exception indicates a particular file, I'm attaching that.
Process.zip

Expected behavior

No error AD0001

Actual behavior

AD0001 shows up

Known workarounds

Ignoring it for now...

Related information

  • SonarC# Version 3.3.0
  • Visual Studio 2015 Enterprise targeted for .NET 4.0
@valhristov
Copy link
Contributor

Hi @jcurl, thanks for the feedback, we will provide a fix as soon as possible!

@valhristov valhristov added blocker Type: Bug Exceptions and blocking issues during analysis. and removed blocker labels Jul 21, 2017
@valhristov valhristov added this to the 6.3 milestone Jul 21, 2017
@jcurl
Copy link
Author

jcurl commented Jul 21, 2017

HI, I just want to mention, that I've had to drop down to v3.2.1 of SonarLint as for some projects it only shows this error and then stops scanning in the IDE. So it appears it wasn't there in 3.2.1.

@Evangelink Evangelink changed the title AD0001: ObjectShouldNotBeDisposedMoreThanOnce Fix S3966: Rule should not throw cast exception Jul 24, 2017
@Evangelink
Copy link
Contributor

Hi @jcurl,

You are right we changed the way the rule works and it seems like we have some uncovered cases.

@ohadschn
Copy link

@Evangelink thank you for fixing this. When will a SonarAnalyzer.CSharp package with this fix be release?

@Evangelink
Copy link
Contributor

Hi @ohadschn we will release the RC today and will release the final Wednesday.

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
5 participants