Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3177

Log4jLogger swallows stack trace if throwable is only present in parameter list and not given explicitly



    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.14.1
    • None
    • SLF4J Bridge
    • None


      I have the feeling that this code below from the Log4jLogger class has a bug. I believe the intention of the code is to use the throwable extracted from the message params of the parametrized message if the throwable parameter was not explicitly provided to the method. But to accomplish this, the condition would need to be if (throwable == null) in the code snippet below. This seems to cause exception stack traces to be swallowed if the throwable is only provided in the params array but not explicitly in the throwable argument.

      public void log(final Marker marker, final String fqcn, final int level, final String message, final Object[] params, Throwable throwable) {
        msg = new ParameterizedMessage(message, params, throwable);
        if (throwable != null) { // I am pretty sure the idea was to use a "==" here and not a "!="
          throwable = msg.getThrowable();

      Source (permalink master at reporting time): https://github.com/apache/logging-log4j2/blob/1a62186816bdd05ba420e01f6ee5a2b139a41816/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java#L371-L374
      Source (latest master): https://github.com/apache/logging-log4j2/blob/master/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java#L371-L374

      I hit the issue in Log4J 2.10.0 but checking the GitHub repo, it appears that this code is still present on the current master branch (see permalink above).


        1. Screenshot 2021-10-25 at 07.39.17.png
          3.11 MB
          Richard Eckart de Castilho
        2. Screenshot 2021-10-25 at 07.36.19.png
          882 kB
          Richard Eckart de Castilho

        Issue Links



              Unassigned Unassigned
              rec Richard Eckart de Castilho
              0 Vote for this issue
              5 Start watching this issue