Make GuardLogStatementJavaUtil configurable
A source code analyzer
Brought to you by:
adangel,
juansotuyo
We're using GuardLogStatementJavaUtil with this given property setting:
<rule ref="rulesets/java/logging-java.xml/GuardLogStatementJavaUtil">
<properties>
<property name="logLevels" value="finest,finer,fine,info" />
<property name="guardsMethods" value="isLoggable" />
</properties>
</rule>
Although we deliberately did not include severe as log level to be checked for being used with a guard method we keep getting this subsequent warning:
GuardLogStatementJavaUtil, Priority: High There is log block not surrounded by if.
when GuardLogStatementJavaUtil rule is applied to a code line like this:
java.util.logging.Logger LOGGER;
...
LOGGER.log(Level.SEVERE, "This is a severe message");
As I understand the use of GuardLogStatementJavaUtil the bold warning should never be issued given our xml setting depicted above.
I changed your ticket to a Feature-Request - as this rule was not configurable.
With the next PMD release, you can configure the logLevels and guardsMethods as you have it in your example.
Please also note that there are two other bugs that are related:
[#1224]: You should not see the violation for simple logging message, only for messages, that use a string concatenation.
[#1227]: Currently, your sample code wasn't detected. Only
LOGGER.severe("This is a severe message")worked. This will be fixed, too.Related
Issues:
#1224Issues:
#1227