Affects PMD Version:
6.40.0+
7.0.0
Rule: GuardLogStatement
Description:
The changes to resolve issue #957 work well when the constant is located in the same class (or at least the same file -- I did not try the scenario of different classes and same file). However, when the concatenated constant used to create the compile-time constant log message comes from elsewhere, PMD still issues a GuardLogStatement false positive.
Code Sample demonstrating the issue:
public class OtherClass { public static final String TERM_MSG = "A terminating log message."; }
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class MyClass { private static final Logger logger = LogManager.getLogger(); public void doSomething() { final Object arg = new Object(); logger.info("Problem message: {}. " + OtherClass.TERM_MSG, arg); } }
Expected outcome:
Because the two concatenated constants result in a compile time constant, there is no work done at log time to create the message string if the log level does not include INFO and so there is no need for a guard statement. This is the same scenario as #957 except in this case, the concatenated constant String is not coming from within the same class.
PMD reports a GuardLogStatement violation at the logger.info(...)
line, but that's wrong. That's a false positive.
Running PMD through: Eclipse PMD Plugin 4.29
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