Menu

#1203 Make GuardLogStatementJavaUtil configurable

PMD-5.1.2
closed
None
PMD
3-Major
Feature-Request
5.1.1
2014-07-20
2014-05-26
No

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.

Discussion

  • Andreas Dangel

    Andreas Dangel - 2014-07-18

    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: #1224
    Issues: #1227

  • Andreas Dangel

    Andreas Dangel - 2014-07-18
    • summary: GuardLogStatementJavaUtil issues warning for severe level not being specified as property --> Make GuardLogStatementJavaUtil configurable
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next
    • Type: Bug --> Feature-Request
     

Log in to post a comment.