Affects PMD Version: 7.0.0-rc1 (Eclipse Plugin 7.0.0.v20230410-1321-rc1)
Rule: category/java/bestpractices.xml/GuardLogStatement
https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#guardlogstatement
Description:
In Java, method references are equivalent to lambdas. While GuardLogStatement recognizes that lambdas are sufficient for frameworks like Log4J2 that have internal guards before executing lambdas, it gives a false positive when a Java method reference is used instead.
Note that I've been using PMD a long time and I haven't had this issue before -- at least not in any relatively recent iteration of PMD 6.x. This is new for me after upgrading to 7.0.0. (I did, however, upgrade Eclipse at the same time).
Code Sample demonstrating the issue:
logger.info("{} - finished with an execution time of {}", applicationInfo::toString, () -> Duration.ofNanos(System.nanoTime() - executionStart));
Expected outcome:
PMD reports a violation ("GuardLogStatement: Logger calls should be surrounded by log level guards.") ..., but that's wrong. That's a false positive.
Running PMD through: Eclipse 4.27
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4