My example code is as simple as that:
import org.apache.log4j.Logger;
public class Test {
public static void main(String args[]){
LOG.info("information log line");
}
private final static Logger LOG = Logger.getLogger(Test.class);
}
It compiles and runs fine with log4j 2.11.0.
For a project that uses jacORB, I need to put the log4j jar files log4j-core-2.11.0.jar
and log4j-api-2.11.0.jar
into a directory that is added to the application via -Djava.endorsed.dirs=someDir
. So, when I copy the log4j-jars into a subdirectory edDir and run the above example with
java -Djava.endorsed.dirs=edDir -Dlog4j.configurationFile=log4j.xml Test
It terminates with this output:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.log4j.Logger.getLogger(Logger.java:41)
at Test.<clinit>(Test.java:7)
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)
... 2 more
It used to work with log4j 2.6. The error described above occured after upgrading to log4j 2.11.0.
Am I doing something wrong? How can I make this work again?
BTW, the JRE is 1.7.
The problem occured when log4j classes were loaded by the Bootstrap classloader, which is the case when the log4j jar files are found in the endorsed directory (-Djava.endorsed.dirs=...
). Log4j didn't handle that correctly (see stacktrace in opening post).
The issue has been resolved in log4j 2.11.1.