ErrorProne.NET
ErrorProne.NET copied to clipboard
[Question] StringFormatCorrectnessAnalyzer throws NRE. How to debug it?
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.
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);
}
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 Will do this week.
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.
Release not done yet. Can anyone help, maybe?
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?
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);
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.