You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (Jira)" <ji...@apache.org> on 2022/03/01 16:47:00 UTC
[jira] (LOG4J2-3420) getlogger() UnsupportedOperationException when loaded by Class.forName()
[ https://issues.apache.org/jira/browse/LOG4J2-3420 ]
Ralph Goers deleted comment on LOG4J2-3420:
-------------------------------------
was (Author: ralph.goers@dslextreme.com):
What happens if you do
{code:java}
public class MyTextField extends JTextField {
final private static Logger logger = LogManager.getLogger(MyTextField.class);
public MyTextField(){}
} {code}
> 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
> Priority: Major
>
> 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}
> 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()
> {code:java}
> public class Stuff {
> static Logger getLogger() {
> 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)