Ernie Rael created LOG4J2-3420:
----------------------------------

             Summary: getlogger() UnsupportedOperationException when loaded by 
Class.forName()
                 Key: LOG4J2-3420
                 URL: https://issues.apache.org/jira/browse/LOG4J2-3420
             Project: Log4j 2
          Issue Type: Bug
          Components: API
    Affects Versions: 2.17.2
         Environment: Several versions of log4j 2.

 

Tried with several versions of jdk (the exception shown is jdk-17).

 
            Reporter: Ernie Rael


Exception arises when this class is used in the NetBeans guiBuilder.
{code:java}
public class MyTextField extends JTextField {
final private static Logger logger = LogManager.getLogger();
public MyTextField(){}
}
{code}
Get the following exception when the bean is selected to drop on the gui.
{noformat}
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)
{noformat}
As a workaround, since I can compile the gui component, I'm invoking 
Stuff.getLogger()
{code:java}
public class Stuff {
static Logger getLogger() {
    Logger logger;
    try {
        return LogManager.getLogger(StackLocatorUtil.getCallerClass(2));
    } catch(UnsupportedOperationException ex) {}
    return LogManager.getRootLogger();
}
}
{code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to