ADDITIONAL SYSTEM INFORMATION :
Windows 10 / openjdk version "21.0.4" 2024-07-16 LTS
A DESCRIPTION OF THE PROBLEM :
SwingNode registers an event listener on node detaching from scene _and_ windows hiding. Both listeners utilize SwingNodeHelper.runOnEDT and, if both are triggered, one of the two fails with NPE because cleanup is already done by the other.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Check the test case attached. Close the window and you'll get NPE in the console.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No unhandled exceptions. This is especially important if not a primary stage (popup) is closed.
ACTUAL -
Exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javafx.swing@22.0.1/com.sun.javafx.embed.swing.newimpl.SwingNodeInteropN.overrideNativeWindowHandle(Native Method)
at javafx.swing@22.0.1/com.sun.javafx.embed.swing.newimpl.SwingNodeInteropN.overrideNativeWindowHandle(SwingNodeInteropN.java:128)
at javafx.swing@22.0.1/javafx.embed.swing.SwingNode.lambda$new$3(SwingNode.java:294)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
---------- BEGIN SOURCE ----------
package de.oowv.application;
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javax.swing.*;
public class JavaSwingNodeCleanupBug extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Hello World!");
SwingNode swingNode = new SwingNode();
SwingUtilities.invokeLater(() -> {
swingNode.setContent(new JLabel("Swing"));
});
stage.setScene(new Scene(new BorderPane(swingNode), 300, 250));
stage.addEventHandler(WindowEvent.WINDOW_HIDDEN, evt -> {
stage.getScene().setRoot(new Group());
});
stage.show();
}
}
---------- END SOURCE ----------
Windows 10 / openjdk version "21.0.4" 2024-07-16 LTS
A DESCRIPTION OF THE PROBLEM :
SwingNode registers an event listener on node detaching from scene _and_ windows hiding. Both listeners utilize SwingNodeHelper.runOnEDT and, if both are triggered, one of the two fails with NPE because cleanup is already done by the other.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Check the test case attached. Close the window and you'll get NPE in the console.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No unhandled exceptions. This is especially important if not a primary stage (popup) is closed.
ACTUAL -
Exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javafx.swing@22.0.1/com.sun.javafx.embed.swing.newimpl.SwingNodeInteropN.overrideNativeWindowHandle(Native Method)
at javafx.swing@22.0.1/com.sun.javafx.embed.swing.newimpl.SwingNodeInteropN.overrideNativeWindowHandle(SwingNodeInteropN.java:128)
at javafx.swing@22.0.1/javafx.embed.swing.SwingNode.lambda$new$3(SwingNode.java:294)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
---------- BEGIN SOURCE ----------
package de.oowv.application;
import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javax.swing.*;
public class JavaSwingNodeCleanupBug extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Hello World!");
SwingNode swingNode = new SwingNode();
SwingUtilities.invokeLater(() -> {
swingNode.setContent(new JLabel("Swing"));
});
stage.setScene(new Scene(new BorderPane(swingNode), 300, 250));
stage.addEventHandler(WindowEvent.WINDOW_HIDDEN, evt -> {
stage.getScene().setRoot(new Group());
});
stage.show();
}
}
---------- END SOURCE ----------
- links to
-
Review(master)
openjdk/jfx/1960