Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why does log4j throw a NullPointerException or print a message about NOPLoggerRepository when shutting down or restarting under Tomcat or during a shutdown hook?

0
Posted

Why does log4j throw a NullPointerException or print a message about NOPLoggerRepository when shutting down or restarting under Tomcat or during a shutdown hook?

0

Tomcat will, by default, clear all static members when unloading classes, however this process can trigger initialization of classes which may then call a class that has been cleared resulting in a NullPointerException or some undesirable behavior. Bug 40212) describes the problem in detail and has a patch which at this writing has not been applied to Tomcat. Glassfish had a similar problem and accepted the patch. The following are recommended to avoid this problem: • Set the org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES system property to false. • Apply the patch from bug 40212 or upgrade to a version that has that patch applied. • Upgrade to log4j 1.2.16 or later to better defend against class loader attack or provide a better diagnostic message when it does occur. It is impossible for log4j to defend against all attacks on its internal state by a class loader. There is a limit to the defensive measures that will be incorporated. For more background, see bugs 4

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123