All Downloads are FREE. Search and download functionalities are using the official Maven repository.

resources.report.rules.pmd.IncorrectlyLoggedException.html Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.8.2
Show newest version


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);
		}
	}
}
       
            




© 2015 - 2024 Weber Informatics LLC | Privacy Policy