[
https://issues.apache.org/jira/browse/LOG4J2-2144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16292574#comment-16292574
]
Prabhu Joseph commented on LOG4J2-2144:
---------------------------------------
Have a User Defined Exception where the StackTrace is hidden for security
purpose.
{code}
public class AuthorizationException extends Exception{
@Override
public void printStackTrace() {
// Do not provide the stack-trace
}
}
{code}
Now a class throws AuthorizationException("not denied") and the catch clause
which logs this exception like below snippet will just print "Exception=" and
there won't be any exception message and StackTrace. The Throwables
toStringList method prints only the StackTrace using printStackTrace(). It's
better to log the message using getMessage() in case if the StackTrace is empty.
{code}
catch(AuthorizationException ae){
log.info("Exception="+ae)
}
{code}
https://github.com/apache/logging-log4j2/blob/dbd2d252a1b4139a9bd9eb213c89f28498db6dcf/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Throwables.java#L61
> Logger does not print message in case if stacktrace is empty for Throwable
> --------------------------------------------------------------------------
>
> Key: LOG4J2-2144
> URL: https://issues.apache.org/jira/browse/LOG4J2-2144
> Project: Log4j 2
> Issue Type: Bug
> Reporter: Prabhu Joseph
>
> There are user defined exceptions which does not print stack trace for
> security purposes. In this case, Logger render method will return empty stack
> trace. We can return the Throwable message if stacktrace is empty while
> logging the exception.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)