diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 4d0dfa6e7b..1c65ef013e 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -21,10 +21,14 @@ For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designe ### Fixed Issues +* java-errorprone + * [#2250](https://github.com/pmd/pmd/issues/2250): \[java] InvalidLogMessageFormat flags logging calls using a slf4j-Marker + ### API Changes ### External Contributions +* [#2251](https://github.com/pmd/pmd/pull/2251): \[java] FP for InvalidLogMessageFormat when using slf4j-Markers - [Kris Scheibe](https://github.com/kris-scheibe) * [#2253](https://github.com/pmd/pmd/pull/2253): \[modelica] Remove duplicated dependencies - [Piotrek Żygieło](https://github.com/pzygielo) {% endtocmaker %} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/InvalidLogMessageFormatRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/InvalidLogMessageFormatRule.java index 37d5236176..46101bdff2 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/InvalidLogMessageFormatRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/InvalidLogMessageFormatRule.java @@ -89,6 +89,11 @@ public class InvalidLogMessageFormatRule extends AbstractJavaRule { final List argumentList = parentNode.getFirstChildOfType(ASTPrimarySuffix.class) .getFirstDescendantOfType(ASTArgumentList.class).findChildrenOfType(ASTExpression.class); + // ignore the first argument if it is a known non-string value, e.g. a slf4j-Marker + if (argumentList.get(0).getType() != null && !argumentList.get(0).getType().equals(String.class)) { + argumentList.remove(0); + } + // remove the message parameter final ASTExpression messageParam = argumentList.remove(0); final int expectedArguments = expectedArguments(messageParam); diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/InvalidLogMessageFormat.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/InvalidLogMessageFormat.xml index 5b44373acc..8f0db82778 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/InvalidLogMessageFormat.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/InvalidLogMessageFormat.xml @@ -780,6 +780,33 @@ public class InvalidLogMessageFormatTest { logger.warn("foo {}", "flibble", "moo", "blah", "blah"); // PMD flags this logger.warn("foo", "flibble", "moo", "blah", "blah"); // PMD doesn't flag this } +} + ]]> + + + + ignore slf4j-Markers when detecting the number of arguments + 2 + 11,17 +