ErrorProne.NET icon indicating copy to clipboard operation
ErrorProne.NET copied to clipboard

[Question] StringFormatCorrectnessAnalyzer throws NRE. How to debug it?

Open aensidhe opened this issue 7 years ago • 9 comments

aensidhe avatar May 15 '18 14:05 aensidhe

Error List window should have a warning emitted by the Roslyn infrastructure, and as part of that warning, you should be able to see a stack trace from the failure.

If you'll provide it, it should be easy to figure out why the NRE is happening.

SergeyTeplyakov avatar May 16 '18 17:05 SergeyTeplyakov

I'm seeing the same.

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Error	AD0001	Analyzer 'ErrorProne.NET.FormatRules.StringFormatCorrectnessAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.	MultiTableExample		1	Active	Analyzer 'ErrorProne.NET.FormatRules.StringFormatCorrectnessAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: MultiTableExample
SyntaxTree: C:\Users\nick\Source\Repos\powerbi\Samples\MultiTableExample\ConsoleTracingInterceptor.cs
SyntaxNode: Console.WriteLine(message, arguments ... [InvocationExpressionSyntax]@[544..581) (18,16)-(18,53)

System.NullReferenceException: Object reference not set to an instance of an object.
   at ErrorProne.NET.SideEffectRules.FormatHelper.ParseFormatString(String format, HashSet`1& usedIndices)
   at ErrorProne.NET.SideEffectRules.FormatHelper.ParseFormatMethodInvocation(InvocationExpressionSyntax invocation, IMethodSymbol symbol, SemanticModel semanticModel)
   at ErrorProne.NET.FormatRules.StringFormatCorrectnessAnalyzer.AnalyzeMethodInvocation(SyntaxNodeAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__43`1.<ExecuteSyntaxNodeAction>b__43_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.

I think it's in my code doing the following

if (arguments == null || arguments.Length == 0)
{
    Console.WriteLine(message);
}
else
{
    Console.WriteLine(message, arguments);
}

nrandell avatar May 17 '18 12:05 nrandell

This is perhaps the most annoying and easily-encountered bug that is in ErrorProne.Net. Could you consider doing a release now that it's fixed?

adimosh avatar Jun 06 '18 16:06 adimosh

@adimosh Will do this week.

SergeyTeplyakov avatar Jun 06 '18 20:06 SergeyTeplyakov

I am seeing this error as well. Not sure if it's my project or with ErrorProne. Please let me know if there is additional data around this that I can provide.

Mike-E-angelo avatar Sep 15 '18 17:09 Mike-E-angelo

Release not done yet. Can anyone help, maybe?

adimosh avatar Sep 28 '18 12:09 adimosh

Is there going to be a release for the package https://www.nuget.org/packages/ErrorProne.NET/ ? It has not been updated since 2016. And it fails with this NRE on a lot of checks. Should we use a different package instead?

adimosh avatar Jan 02 '19 15:01 adimosh

Same issue here, this code triggered the problem for me:

public static string Format(string formatString, params object[] values) =>
    string.Format(CultureInfo.InvariantCulture, formatString, values);

sunsided avatar Apr 21 '20 14:04 sunsided

Wait, it might be that the issue is that we're using ErrorProne.NET when we should really be using ErrorProne.NET.CoreAnalyzers. This is at least hinted at in https://github.com/SergeyTeplyakov/ErrorProne.NET/issues/114#issuecomment-469051246.

sunsided avatar Apr 28 '20 17:04 sunsided