GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] InvalidLogMessageFormat rule produces a NPE · Issue #4185 · pmd/pmd

[java] InvalidLogMessageFormat rule produces a NPE #4185

New issue
Copy link
New issue
Copy link
Closed
#4191
Closed
[java] InvalidLogMessageFormat rule produces a NPE#4185
#4191
Copy link
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
6.52.0

Description

@nvervelle
nvervelle
opened on Oct 31, 2022
Issue body actions

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

Activity

  1. nvervelle
    added
    a:bugPMD crashes or fails to analyse a file.
    on Oct 31, 2022
  2. nvervelle
    changed the title [-]InvalidLogMessageFormat rule produces a NPE[/-] [+][Java] InvalidLogMessageFormat rule produces a NPE[/+] on Oct 31, 2022
  3. nvervelle
    changed the title [-][Java] InvalidLogMessageFormat rule produces a NPE[/-] [+][java] InvalidLogMessageFormat rule produces a NPE[/+] on Oct 31, 2022
  4. adangel
    added this to the 6.52.0 milestone on Nov 3, 2022
  5. adangel
    added a commit that references this issue on Nov 3, 2022

    [java] Fix NPE in InvalidLogMessageFormat

    This issue will close once commit dcbc48b is merged into the 'main' branch.
    dcbc48b
  6. oowekyala
    closed this as completedin dcbc48bon Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.52.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.