resources.report.rules.pmd.IncorrectlyLoggedException.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
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);
}
}
}