You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "nielsm5 (via GitHub)" <gi...@apache.org> on 2026/01/21 16:27:13 UTC

[I] ThrowableExtendedStackTraceRenderer catches Exception but not Error [logging-log4j2]

nielsm5 opened a new issue, #4028:
URL: https://github.com/apache/logging-log4j2/issues/4028

   ## Description
   
   There is a loadClass method in the `ThrowableExtendedStackTraceRenderer`.
   
   
   ```java
           private static Class<?> loadClass(final ClassLoader loader, final String className) {
               for (final ClassLoadingStrategy strategy : CLASS_LOADING_STRATEGIES) {
                   try {
                       final Class<?> clazz = strategy.run(loader, className);
                       if (clazz != null) {
                           return clazz;
                       }
                   } catch (final Exception ignored) {
                       // Do nothing
                   }
               }
               return null;
           }
   ```
   Which when unable to lookup the given class, should do nothing. But Classloaders throw NoClassDefFoundError which is an `Error` and thus not caught. This breaks log4j2, causing our app to log a beautify 'log4j2 cannot log something exception` and not the actual message+stacktrace it should log!
   
   ## Configuration
   
   **Version:** 2.25.3
   
   **Operating system:** Windows, unrelated to this.
   
   **JDK:** 21 and 25, also unrelated.
   
   ## Logs
   
   ```
   2026-01-21T13:27:17.646390600Z main ERROR An exception occurred processing Appender application-log-appender
   org.apache.logging.log4j.core.appender.AppenderLoggingException: java.lang.NoClassDefFoundError: org/frankframework/core/IPushingListener
   	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:164)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:133)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:124)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:88)
   	at org.apache.logging.log4j.core.appender.routing.RoutingAppender.append(RoutingAppender.java:256)
   	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:160)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:133)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:124)
   	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:88)
   	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:711)
   	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:669)
   	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:645)
   	at org.apache.logging.log4j.core.config.LoggerConfig.logParent(LoggerConfig.java:702)
   	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:671)
   	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:645)
   	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:589)
   	at org.apache.logging.log4j.core.config.DefaultReliabilityStrategy.log(DefaultReliabilityStrategy.java:73)
   	at org.apache.logging.log4j.core.Logger.log(Logger.java:187)
   	at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2970)
   	at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2922)
   	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2904)
   	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2648)
   	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:2587)
   	at org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:824)
   .. many  many more
   ```
   
   ## Reproduction
   
   Very difficult, requires custom classloaders.
   https://github.com/frankframework/frankframework/issues/10312


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ThrowableExtendedStackTraceRenderer catches Exception but not Error [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on issue #4028:
URL: https://github.com/apache/logging-log4j2/issues/4028#issuecomment-3783009754

   @nielsm5, would you be interested in contributing this fix along with a test?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ThrowableExtendedStackTraceRenderer catches Exception but not Error [logging-log4j2]

Posted by "chanani (via GitHub)" <gi...@apache.org>.
chanani commented on issue #4028:
URL: https://github.com/apache/logging-log4j2/issues/4028#issuecomment-3815023384

   Hi @nielsm5 @vy , I'd like to work on this issue.
   
   **Expected fix:** Change the catch block from `Exception` to `Throwable`:
   ```java
   } catch (final Throwable ignored) {  // Changed from Exception
       // Do nothing
   }
   ```
   
   This will properly handle `NoClassDefFoundError` and prevent the AppenderLoggingException.
   
   I'll include a test case for custom classloaders throwing `NoClassDefFoundError`. 
   
   May I submit a PR for this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ThrowableExtendedStackTraceRenderer catches Exception but not Error [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on issue #4028:
URL: https://github.com/apache/logging-log4j2/issues/4028#issuecomment-3907628527

   > I tried but while testing the `ThrowableExtendedStackTraceRenderer` uses `~[?:?]`. I'm also not sure if it's easy to test this. It requires custom classloading..
   
   @nielsm5, maybe using reflection to manipulate `CLASS_LOADING_STRATEGIES` and having an entry there which throws an `Error`?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ThrowableExtendedStackTraceRenderer catches Exception but not Error [logging-log4j2]

Posted by "nielsm5 (via GitHub)" <gi...@apache.org>.
nielsm5 commented on issue #4028:
URL: https://github.com/apache/logging-log4j2/issues/4028#issuecomment-3790203644

   > [@nielsm5](https://github.com/nielsm5), would you be interested in contributing this fix along with a test?
   
   I tried but while testing the `ThrowableExtendedStackTraceRenderer` uses `~[?:?]`.
   I'm also not sure if it's easy to test this. It requires custom classloading..


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ThrowableExtendedStackTraceRenderer catches Exception but not Error [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on issue #4028:
URL: https://github.com/apache/logging-log4j2/issues/4028#issuecomment-3907611528

   @chanani, I grant you all the rights in the universe to submit a PR fixing the issue.
   
   P.S. You don't need any permission from anyone to submit fixes (real fixes!) to Log4j. Make sure that `./mvnw verify` is happy and there is an associated changelog entry.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ThrowableExtendedStackTraceRenderer catches Exception but not Error [logging-log4j2]

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy closed issue #4028: ThrowableExtendedStackTraceRenderer catches Exception but not Error
URL: https://github.com/apache/logging-log4j2/issues/4028


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org