Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Bug
-
2.17.2
-
None
-
None
-
Several versions of log4j 2.
Tried with several versions of jdk (the exception shown is jdk-17).
Description
Exception arises when this class is used in the NetBeans guiBuilder.
public class MyTextField extends JTextField { final private static Logger logger = LogManager.getLogger(); public MyTextField(){} }
Get the following exception when the bean is selected to drop on the gui.
INFO [org.netbeans.modules.form.MetaComponentCreator]: Cannot load component class play.MyTextField from unknown source. The class itself was found, but there was a problem initializing it, e.g. due to an exception in static initializer, or failure in loading an additional class needed by the component class. Check the attached exception. java.lang.UnsupportedOperationException: No class provided, and an appropriate one cannot be found. at org.apache.logging.log4j.LogManager.callerClass(LogManager.java:573) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:598) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:585) at play.MyTextField.<clinit>(MyTextField.java:35) Caused: java.lang.ExceptionInInitializerError at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:467) at org.netbeans.modules.form.project.ClassPathUtils.loadClass(ClassPathUtils.java:89)
This exception similarly occurs with clazz.newInstance(), which is sometimes used by the guiBuilder. It also occurs if the getLogger is in the constructor rather than a static.
As a workaround, since I can compile the gui component, I'm invoking Stuff.getLogger()
public class Stuff { static Logger getLogger() { try { return LogManager.getLogger(StackLocatorUtil.getCallerClass(2)); } catch(UnsupportedOperationException ex) {} return LogManager.getRootLogger(); } }