GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [java] GuardLogStatement recognizes that a string is a compile-time constant expression only if at first position · Issue #5820 · pmd/pmd Closed Labels a:false-positivePMD flags a piece of code that is not problematic Milestone DescriptionAffects PMD Version: 7.14.0 (in fact since 7.5.0) Rule: https://docs.pmd-code.org/pmd-doc-7.14.0/pmd_rules_java_bestpractices.html#guardlogstatement Description: While this detection also worked with PMD 6.45.0 until PMD 7.4.0 independent of the position of the compile-time constant expression in the method call, PMD 7.14.0 reports a violation (false positive) if the compile-time constant expression is not the first parameter, e.g. if a marker is the first parameter, or if the compile-time constant expression follows later on (more realistic use case than line 13 below: a specialized logger implementation is used that expects the message being built of long compile-time constant strings with line wrapping as third parameter). Code Sample demonstrating the issue: import org.slf4j.*; public class MyLogger { private static final Logger LOGGER = LoggerFactory.getLogger(MyLogger.class); public static void main(String[] args) { LOGGER.debug("Part1" + " Part2"); // ok final Marker marker = MarkerFactory.getMarker("myMarker"); LOGGER.debug(marker, "Part3 " + "Part4"); // false-positive GuardLogStatement LOGGER.debug(marker, "Message={}", "Part3 " + "Part4"); // false-positive GuardLogStatement } } Expected outcome: PMD reports a violation at line 11 as well as line 13, but that's wrong. That's a false positive. Running PMD through: Gradle Activity
MetadataMetadataAssigneesLabelsa:false-positivePMD flags a piece of code that is not problematic TypeProjectsMilestoneRelationshipsDevelopmentIssue 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. |