apache / apache/netbeans

Parent GUI Builder can't load child component using Log4j2 logger without class name

Open
#5,791 0 comments 0 reactions 0 assignees View on GitHub
FormDesigner Java kind:bug needs:triage
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 17

### What happened

### Issue
If you create a custom Java Swing GUI component that declares an Apache log4j2 Logger without specifying the class, and then try to use that component in another custom Java Swing GUI component using the GUI builder, the parent GUI builder fails to load the child component with a nested UnsupportedOperationException from log4j2. See attached sample stacktrace.

### Expected Behavior
The GUI builder for the parent should be able to load the child component without throwing the UnsupportedOperationException.

### Notes
Interestingly, the GUI builder for the child component itself is fine - it will load without any problems. It's just when the parent container tries to load that the GUI builder throws an error.

This is presumably related to log4j2 being a multi-release jar, and changes in JDK 9+. If you use an older version of Netbeans that can run on JDK 8 (I tried it with Netbeans 12.6), the GUI builder has no issues.

### Workaround
Specify the class name when creating an Apache log4j2 Logger.

[sample_stacktrace.txt](https://github.com/apache/netbeans/files/11180971/sample_stacktrace.txt)

### How to reproduce

In Netbeans 17 running on JDK 11+, create a custom Swing component - this can be done either using one of the GUI Builder forms or just manually creating the class. Declare an Apache log4j2 Logger property without specifying the class name:

Create another Swing GUI JPanel form class. Try to drag the child component into the new JPanel form in the GUI Builder - this will trigger an ExceptionInitializerError with a nested UnsupportedOperationException.

Alternatively, use LOG declarations that specify the class names and drag the ChildPanel/ChildTable into the ParentPanel GUI Builder. Close the ParentPanel class and modify the ChildPanel/ChildTable to use the LOG declarations that don't specify the class name. Then re-open the ParentPanel class to reload the GUI Builder and trigger exceptions when initializing the child components.

Sample stacktrace attached.

```java
// ChildPanel created using Netbeans "new JPanel Form..." creation
// Note that the GUI Builder for this class displays with no issues, no matter how the LOG is created.
public class ChildPanel extends javax.swing.JPanel {
// Using this declaration causes an error in the parent GUI Builder
private static final Logger LOG = LogManager.getLogger();
// Specifying the class removes the error
// private static final Logger LOG = LogManager.getLogger(ChildPanel.class);
}

// ChildTable written manually, without a GUI Builder
public class ChildTable extends JTable {
// Using this declaration causes an error in the parent GUI Builder
private static final Logger LOG = LogManager.getLogger();
// Specifying the class removes the error
// private static final Logger LOG = LogManager.getLogger(ChildTable.class);
}

// ParentPanel created using Netbeans "new JPanel Form..." creation
// In GUI Builder, try to drag either ChildPanel or ChildTable into the panel to trigger an exception.
public class ParentPanel extends javax.swing.JPanel {
}
```

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Windows 10 Pro

### JDK

JDK 17

### Apache NetBeans packaging

Apache NetBeans provided installer

### Anything else

This error occurs no matter what JDK the Java project uses - it's dependent on the JDK version used by Netbeans, not on the project JDK.

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Start with the attached sample_stacktrace.txt and the NetBeans GUI Builder component-loading path, then reproduce the failure on JDK 11 or newer using the ChildPanel or ChildTable and ParentPanel example. The work is done when the parent GUI Builder loads a child component whose Log4j2 logger uses LogManager.getLogger() without throwing the reported exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
desktop, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.