resources.report.rules.pmd.IncorrectlyLoggedException.html Maven / Gradle / Ivy
IncorrectlyLoggedException
IncorrectlyLoggedException
Do not rely on an Exception's toString() representation when logging errors,
as it may not contain enough information (e.g. the Stacktrace). Use the
log.error(String, Throwable) method instead.
This rule is defined by the following XPath expression:
//CatchStatement/Block/BlockStatement/Statement
[ends-with(StatementExpression/PrimaryExpression/PrimaryPrefix/Name/@Image, '.error')]
[StatementExpression/PrimaryExpression/PrimarySuffix/Arguments/ArgumentList/Expression/AdditiveExpression/PrimaryExpression/PrimaryPrefix/Name/@Image = ../../../FormalParameter/VariableDeclaratorId/@Image]
Example:
public class MyClass
{
private static final Logger log = Logger.get(MyClass.class);
public byte[] getData()
{
try
{
return StreamUtils.read(new FileInputStream("data"));
}
catch (IOException e)
{
//log.error("Bad" + e);
//log.error("Ok" + e.getMessage());
log.error("Better", e);
}
}
}