Affects PMD Version:
6.53.0+
7.0.0
Rule: GuardLogStatement
Description:
I have an additional if between the guard method and the actual call to a log method (see example below). In the else I'm directly calling a (simple getter) method to provide an argument to the log method, which triggers the need for a guard. This raises a violation: Logger calls should be surrounded by log level guards.
The rule does not recognize that there's a guard around it, just not as direct parent in the syntax tree.
Code Sample demonstrating the issue:
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class Foo {
private static final Logger LOG = LogManager.getLogger(Foo.class);
public void test(String arg1) {
if (LOG.isWarnEnabled()) {
if (someCondition) {
String msg = "Message 1 with one argument: ";
LOG.warn(msg + arg1);
} else {
String msg = "Message 2 with two arguments: {}, {}.";
LOG.warn(msg + arg1);
}
}
}
}
Expected outcome:
PMD should look further around it to detect a guard method.
Running PMD through: Maven | Eclipse Plug-in
Affects PMD Version:
6.53.0+
7.0.0
Rule: GuardLogStatement
Description:
I have an additional
ifbetween the guard method and the actual call to a log method (see example below). In theelseI'm directly calling a (simple getter) method to provide an argument to the log method, which triggers the need for a guard. This raises a violation:Logger calls should be surrounded by log level guards.The rule does not recognize that there's a guard around it, just not as direct parent in the syntax tree.
Code Sample demonstrating the issue:
Expected outcome:
PMD should look further around it to detect a guard method.
Running PMD through: Maven | Eclipse Plug-in