Skip to content

[java] UseCorrectExceptionLogging FP in 6.31.0 #3100

@testation21

Description

@testation21

Affects PMD Version: 6.31.0

Rule: UseCorrectExceptionLogging
https://pmd.github.io/pmd-6.31.0/pmd_rules_java_errorprone.html#usecorrectexceptionlogging

Description:
Apache chukwa has ExceptionUtils which contains getStackTrace().
It is for Getting the stack trace from a Throwable as a String.
Apache hadoop has also StringUtils which contains stringifyException().
it returns a string with exception name and call stack

Code Sample demonstrating the issue:

import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.chukwa.util.ExceptionUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class TestUseCorrectExceptionLogging{
        private static Log log = LogFactory.getLog(TestUseCorrectExceptionLogging.class);
        public void testPMD(){
                try{
                        //something
                }
                catch(Exception e){
                        log.error(ExceptionUtil.getStackTrace(e));
                        log.error(StringUtils.stringifyException(e));
                }
        }
}

Expected outcome:
Don't show any alarm.

Running PMD through: CLI

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions