JFXPanel may cause a NPE on Window.close():
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javafx.embed.swing.JFXPanel.getInputMethodRequests(JFXPanel.java:764)
at sun.awt.im.InputMethodAdapter.haveActiveClient(InputMethodAdapter.java:61)
at sun.awt.windows.WInputMethod.deactivate(WInputMethod.java:340)
at sun.awt.im.InputContext.deactivateInputMethod(InputContext.java:492)
at sun.awt.im.InputContext.focusLost(InputContext.java:458)
at sun.awt.im.InputContext.removeNotify(InputContext.java:627)
at java.awt.Component.removeNotify(Component.java:7010)
at java.awt.Container.removeNotify(Container.java:2820)
at javax.swing.JComponent.removeNotify(JComponent.java:4764)
at javafx.embed.swing.JFXPanel.removeNotify(JFXPanel.java:783)
at java.awt.Container.removeNotify(Container.java:2804)
at javax.swing.JComponent.removeNotify(JComponent.java:4764)
at java.awt.Container.removeNotify(Container.java:2804)
at javax.swing.JComponent.removeNotify(JComponent.java:4764)
at java.awt.Container.removeNotify(Container.java:2804)
at javax.swing.JComponent.removeNotify(JComponent.java:4764)
at javax.swing.JRootPane.removeNotify(JRootPane.java:765)
at java.awt.Container.removeNotify(Container.java:2804)
at java.awt.Window.removeNotify(Window.java:782)
at java.awt.Frame.removeNotify(Frame.java:1041)
at java.awt.Window$1DisposeAction.run(Window.java:1194)
at java.awt.Window.doDispose(Window.java:1210)
at java.awt.Window.dispose(Window.java:1151)
The problem seems to be caused by a concurrent modification of JFXPanel.scenePeer by:
JavaFX Application Thread@1193, prio=6, in group 'main', status: 'RUNNING'
at javafx.embed.swing.JFXPanel$HostContainer.setEmbeddedScene(JFXPanel.java:818)
at com.sun.javafx.tk.quantum.EmbeddedScene.setStage(EmbeddedScene.java:99)
at com.sun.javafx.tk.quantum.GlassStage.setScene(GlassStage.java:96)
at com.sun.javafx.tk.quantum.EmbeddedStage.setScene(EmbeddedStage.java:62)
at javafx.stage.Window$9.invalidated(Window.java:797)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:143)
at javafx.stage.Window.setShowing(Window.java:841)
at javafx.stage.Window.hide(Window.java:866)
at javafx.embed.swing.JFXPanel.lambda$removeNotify$6(JFXPanel.java:775)
at javafx.embed.swing.JFXPanel$$Lambda$120.754166886.run(Unknown Source:-1)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$63.567723434.run(Unknown Source:-1)
at java.security.AccessController.doPrivileged(AccessController.java:-1)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$62.1639462272.run(Unknown Source:-1)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(WinApplication.java:-1)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$50.1264502830.run(Unknown Source:-1)
at java.lang.Thread.run(Thread.java:745)
which was trigged at at: JFXPanel.lambda$removeNotify$6(JFXPanel.java:775)
and seems to clear scenePeer just after AWT-EventQueue tests: if (scenePeer == null) at line 761.
It seems to be a race condition which surprisingly happens to me by 50% when closing the window.
This is a small sample to verify the problem:
public class Main {
public static void main(String ... args) {
SwingUtilities.invokeLater(Main::new);
}
final JFrame frame = new JFrame();
final JFXPanel panel = new JFXPanel();
public Main() {
frame.setSize(40, 60);
frame.add(panel);
Platform.runLater(this::setupScene);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
void setupScene() {
Button ok = new Button("ok");
ok.setDefaultButton(true);
ok.setOnAction(this::close);
Scene scene = new Scene(ok);
panel.setScene(scene);
}
void close(ActionEvent e) {
SwingUtilities.invokeLater(() -> {
frame.setVisible(false);
frame.dispose();
});
}
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javafx.embed.swing.JFXPanel.getInputMethodRequests(JFXPanel.java:764)
at sun.awt.im.InputMethodAdapter.haveActiveClient(InputMethodAdapter.java:61)
at sun.awt.windows.WInputMethod.deactivate(WInputMethod.java:340)
at sun.awt.im.InputContext.deactivateInputMethod(InputContext.java:492)
at sun.awt.im.InputContext.focusLost(InputContext.java:458)
at sun.awt.im.InputContext.removeNotify(InputContext.java:627)
at java.awt.Component.removeNotify(Component.java:7010)
at java.awt.Container.removeNotify(Container.java:2820)
at javax.swing.JComponent.removeNotify(JComponent.java:4764)
at javafx.embed.swing.JFXPanel.removeNotify(JFXPanel.java:783)
at java.awt.Container.removeNotify(Container.java:2804)
at javax.swing.JComponent.removeNotify(JComponent.java:4764)
at java.awt.Container.removeNotify(Container.java:2804)
at javax.swing.JComponent.removeNotify(JComponent.java:4764)
at java.awt.Container.removeNotify(Container.java:2804)
at javax.swing.JComponent.removeNotify(JComponent.java:4764)
at javax.swing.JRootPane.removeNotify(JRootPane.java:765)
at java.awt.Container.removeNotify(Container.java:2804)
at java.awt.Window.removeNotify(Window.java:782)
at java.awt.Frame.removeNotify(Frame.java:1041)
at java.awt.Window$1DisposeAction.run(Window.java:1194)
at java.awt.Window.doDispose(Window.java:1210)
at java.awt.Window.dispose(Window.java:1151)
The problem seems to be caused by a concurrent modification of JFXPanel.scenePeer by:
JavaFX Application Thread@1193, prio=6, in group 'main', status: 'RUNNING'
at javafx.embed.swing.JFXPanel$HostContainer.setEmbeddedScene(JFXPanel.java:818)
at com.sun.javafx.tk.quantum.EmbeddedScene.setStage(EmbeddedScene.java:99)
at com.sun.javafx.tk.quantum.GlassStage.setScene(GlassStage.java:96)
at com.sun.javafx.tk.quantum.EmbeddedStage.setScene(EmbeddedStage.java:62)
at javafx.stage.Window$9.invalidated(Window.java:797)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:143)
at javafx.stage.Window.setShowing(Window.java:841)
at javafx.stage.Window.hide(Window.java:866)
at javafx.embed.swing.JFXPanel.lambda$removeNotify$6(JFXPanel.java:775)
at javafx.embed.swing.JFXPanel$$Lambda$120.754166886.run(Unknown Source:-1)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$63.567723434.run(Unknown Source:-1)
at java.security.AccessController.doPrivileged(AccessController.java:-1)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$62.1639462272.run(Unknown Source:-1)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(WinApplication.java:-1)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$50.1264502830.run(Unknown Source:-1)
at java.lang.Thread.run(Thread.java:745)
which was trigged at at: JFXPanel.lambda$removeNotify$6(JFXPanel.java:775)
and seems to clear scenePeer just after AWT-EventQueue tests: if (scenePeer == null) at line 761.
It seems to be a race condition which surprisingly happens to me by 50% when closing the window.
This is a small sample to verify the problem:
public class Main {
public static void main(String ... args) {
SwingUtilities.invokeLater(Main::new);
}
final JFrame frame = new JFrame();
final JFXPanel panel = new JFXPanel();
public Main() {
frame.setSize(40, 60);
frame.add(panel);
Platform.runLater(this::setupScene);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
void setupScene() {
Button ok = new Button("ok");
ok.setDefaultButton(true);
ok.setOnAction(this::close);
Scene scene = new Scene(ok);
panel.setScene(scene);
}
void close(ActionEvent e) {
SwingUtilities.invokeLater(() -> {
frame.setVisible(false);
frame.dispose();
});
}
}
- duplicates
-
JDK-8098836 various NullPointerException in JFXPanel
-
- Resolved
-