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

[java] InvalidLogMessageFormat rule produces a NPE #4185

Closed
nvervelle opened this issue Oct 31, 2022 · 0 comments · Fixed by #4191
Closed

[java] InvalidLogMessageFormat rule produces a NPE #4185

nvervelle opened this issue Oct 31, 2022 · 0 comments · Fixed by #4191
Labels
a:bug PMD crashes or fails to analyse a file.
Milestone

Comments

@nvervelle
Copy link

Affects PMD Version: 6.51.0

Description:

When using StructuredArguments, it may be normal to have additional arguments to the ones used directly in the message format. With such situations, the InvalidLogMessageFormat rule may throw a NPE when trying to remove the last parameter if it is a Throwable.

The instruction decl.getName().equals(varName) in isLambdaParameter() doesn't check that decl.getName() doesn't return null.

Exception Stacktrace:

Exception applying rule InvalidLogMessageFormat on file xxx.java, continuing with next rule
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "net.sourceforge.pmd.lang.symboltable.NameDeclaration.getName()" is null
        at net.sourceforge.pmd.lang.java.rule.errorprone.InvalidLogMessageFormatRule.isLambdaParameter(InvalidLogMessageFormatRule.java:249)
        at net.sourceforge.pmd.lang.java.rule.errorprone.InvalidLogMessageFormatRule.removeThrowableParam(InvalidLogMessageFormatRule.java:231)
        at net.sourceforge.pmd.lang.java.rule.errorprone.InvalidLogMessageFormatRule.visit(InvalidLogMessageFormatRule.java:164)
        at net.sourceforge.pmd.lang.java.ast.ASTName.jjtAccept(ASTName.java:38)
        at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.visitAll(AbstractJavaRule.java:164)
        at net.sourceforge.pmd.lang.java.rule.AbstractJavaRule.apply(AbstractJavaRule.java:158)
        at net.sourceforge.pmd.lang.internal.DefaultRulechainVisitor.visit(DefaultRulechainVisitor.java:26)
        at net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor.visitAll(AbstractRuleChainVisitor.java:101)
        at net.sourceforge.pmd.RuleChain.apply(RuleChain.java:72)
        at net.sourceforge.pmd.RuleSets.apply(RuleSets.java:160)
        at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:209)
        at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:118)
        at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:100)
        at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:62)
        at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:85)
        at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:29)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)

Code Sample demonstrating the issue:

          LOGGER.info(
              LogMarker.OBSERVABILITY.getMarker(),
              "End span {} in {}ms",
              kindMessage(span),
              duration.toMillis(),
              StructuredArguments.keyValue("traceId", "Text"));

Steps to reproduce:

Just running ./gradlew build

Running PMD through: Gradle

@nvervelle nvervelle added the a:bug PMD crashes or fails to analyse a file. label Oct 31, 2022
@nvervelle nvervelle changed the title InvalidLogMessageFormat rule produces a NPE [Java] InvalidLogMessageFormat rule produces a NPE Oct 31, 2022
@nvervelle nvervelle changed the title [Java] InvalidLogMessageFormat rule produces a NPE [java] InvalidLogMessageFormat rule produces a NPE Oct 31, 2022
@adangel adangel added this to the 6.52.0 milestone Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants