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

SA1008 threw a NullReferenceException #2354

Closed
appel1 opened this issue May 19, 2017 · 2 comments · Fixed by #3741
Closed

SA1008 threw a NullReferenceException #2354

appel1 opened this issue May 19, 2017 · 2 comments · Fixed by #3741

Comments

@appel1
Copy link

appel1 commented May 19, 2017

Using StyleCopAnalyzers 1.0 in VS2017 for a .NET 4.5 project, C#6. While refactoring I got the following error. At some point during my refactorings the file referenced in the error was removed, don't know if that is related or if this error occurred before that.

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Warning	AD0001	Analyzer 'StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.	<project>	1	Active	Analyzer 'StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly' threw the following exception:
'Exception occurred with following context:
Compilation: <project>
SyntaxTree: <source path>

System.NullReferenceException: Object reference not set to an instance of an object.
   at StyleCop.Analyzers.Helpers.LocationHelpers.GetLineSpan(SyntaxToken token)
   at StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly.HandleOpenParenToken(SyntaxTreeAnalysisContext context, SyntaxToken token)
   at StyleCop.Analyzers.SpacingRules.SA1008OpeningParenthesisMustBeSpacedCorrectly.HandleSyntaxTree(SyntaxTreeAnalysisContext context)
   at StyleCop.Analyzers.AnalyzerExtensions.<>c__DisplayClass2_0.<RegisterSyntaxTreeActionHonorExclusions>b__0(SyntaxTreeAnalysisContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass41_0.<ExecuteSyntaxTreeActionsCore>b__0()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info)
-----
'.
@vweijsters vweijsters added the bug label May 20, 2017
@vweijsters
Copy link
Contributor

I had a quick look at the sources and I don't see an obvious bug there. The call stack indicates that either the token being processed (the opening parenthesis) or the previous token has a SyntaxTree property that returns null. I can't quite figure out yet under what circumstances that can happen.

@bjornhellander
Copy link
Contributor

This happens for example if there is no token before the opening parenthesis, since GetPreviousToken would then return a default SyntaxToken. Seems a bit unlikely that that was what happened, but it could be. I don't see any other possibility. I am creating a pull request.

bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 3, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 3, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 3, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 3, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 16, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 17, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 19, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 19, 2023
@sharwell sharwell added the fixed label Dec 19, 2023
@sharwell sharwell added this to the 1.2-beta.next milestone Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants