I recently encountered the following issue when trying to start a new Java 11 project.
I am using Log4j2 (2.11.1) for logging, and was obtaining a static 'LOG' object in the normal way:
private static final Logger LOG = LogManager.getLogger();
At runtime, I received the following message:
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance. Exception in thread "main" java.lang.ExceptionInInitializerError Caused by: java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found. at org.apache.logging.log4j.LogManager.callerClass(LogManager.java:555) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:580) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:567) at app.App.<clinit>(App.java:11)
Which indicates that the code was unable to use reflection to obtain the current class name. According to the log4j changelog, this issue had been fixed in 2.10.0 (prior to the version I was using). However, the issue had been fixed by using a multi-release jar.
In my project, I was creating a shaded jar using the maven-shade-plugin. But was not enabling the multi-release features (because my project does not need to support older versions of java). So, the multi-release class files from my dependencies were being included in the shaded jar, but not being loaded.
To fix the problem, I simply had to add
to my manifest, and everything started working.