Description
When log4j2 classes are loaded via the Bootstrap classloader, creating a Logger (LogManager.getLogger()) causes a NullPointerException:
Exception in thread "main" java.lang.ExceptionInInitializerError
at Test.<clinit>(Test.java:6)
Caused by: java.lang.NullPointerException
at org.apache.logging.log4j.util.LoaderUtil.getClassLoaders(LoaderUtil.java:115)
at org.apache.logging.log4j.util.ProviderUtil.<init>(ProviderUtil.java:66)
at org.apache.logging.log4j.util.ProviderUtil.lazyInit(ProviderUtil.java:146)
at org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:130)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:89)
... 1 more
To reproduce this behavior I put the log4j jar files (log4j-api and log4j-core) into a dedicated directory and start my test program with -Djava.endorsed.dirs=dirname. Classes from jars in that directory are loaded using the Bootstrap classloader.
The issue came with 2.9.1. It worked with 2.9.0 and earlier versions.