Menu

#554 Port Apache Commons Logging rule to Java Logging Rules

open
nobody
rules (229)
5
2014-02-18
2010-11-29
Anonymous
No

The UseCorrectExceptionLogging rule defined in the logging-jakarta-commons ruleset is equally valid for Java (log4j) logging. The rule should be copied from one to the other, with the single word "Log" changed to "Logger" - see @Image='Logger' below. Here's the finished version, which works for log4j errors:

//CatchStatement/Block/BlockStatement/Statement/StatementExpression
/PrimaryExpression[PrimaryPrefix/Name[starts-with(@Image,
concat(ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration
[Type//ClassOrInterfaceType[@Image='Logger']
]
/VariableDeclarator/VariableDeclaratorId/@Image, '.'))]]
[PrimarySuffix/Arguments[@ArgumentCount='1']]
[PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Image]

Discussion


Log in to post a comment.