Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8096047

NullPointerException in JFXPanel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u40, 8u45
    • javafx

      I'm encountering a NullPointerException when removing a JFXPanel from a Swing hierarchy. Unfortunately, I'm unable to put together a set of steps to reproduce the issue reliably.

      The exception is thrown at line 929 of the JFXPanel class, where the panel's SwingDnD object is dereferenced without a null check. Simply adding a null check seems to fix the issue:

              @Override
              public void setEmbeddedScene(EmbeddedSceneInterface embeddedScene) {
                  if (scenePeer == embeddedScene) {
                      return;
                  }
                  scenePeer = embeddedScene;
                  if (scenePeer == null) {
                      invokeOnClientEDT(() -> {
                          dnd.removeNotify();
                          dnd = null;
                      });
                      return;
                  }
                  ...

      Should become

              @Override
              public void setEmbeddedScene(EmbeddedSceneInterface embeddedScene) {
                  if (scenePeer == embeddedScene) {
                      return;
                  }
                  scenePeer = embeddedScene;
                  if (scenePeer == null) {
                      invokeOnClientEDT(() -> {
                          if (dnd != null) {
                              dnd.removeNotify();
                          }
                          dnd = null;
                      });
                      return;
                  }



      This is the stacktrace:
                                  java.lang.NullPointerException
                                   at javafx.embed.swing.JFXPanel$HostContainer.lambda$setEmbeddedScene$53(JFXPanel.java:929)
                                   at javafx.embed.swing.JFXPanel$HostContainer$$Lambda$18859/13594061.run(Unknown Source)
                                   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
                                   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:749)
                                   at java.awt.EventQueue.access$500(EventQueue.java:97)
                                   at java.awt.EventQueue$3.run(EventQueue.java:702)
                                   at java.awt.EventQueue$3.run(EventQueue.java:696)
                                   at java.security.AccessController.doPrivileged(Native Method)
                                   at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
                                   at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
                                   at java.awt.EventQueue$4.run(EventQueue.java:724)
                                   at java.awt.EventQueue$4.run(EventQueue.java:722)
                                   at java.security.AccessController.doPrivileged(Native Method)
                                   at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
                                   at java.awt.EventQueue.dispatchEvent(EventQueue.java:721)
                                   at jSSS.jgui.sssworker.SSSMouseBlocker.dispatchEvent(SSSMouseBlocker.java:105)
                                   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
                                   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
                                   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
                                   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
                                   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
                                   at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

      The call into invokeOnClientEDT() has the following stacktrace:
      at javafx.embed.swing.JFXPanel$HostContainer.setEmbeddedScene(JFXPanel.java:928)
      at com.sun.javafx.tk.quantum.EmbeddedScene.setStage(EmbeddedScene.java:100)
      at com.sun.javafx.tk.quantum.GlassStage.setScene(GlassStage.java:96)
      at com.sun.javafx.tk.quantum.EmbeddedStage.setScene(EmbeddedStage.java:63)
      at javafx.stage.Window$9.invalidated(Window.java:866)
      at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
      at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:144)
      at javafx.stage.Window.setShowing(Window.java:910)
      at javafx.stage.Window.hide(Window.java:935)
      at javafx.embed.swing.JFXPanel.lambda$removeNotify$50(JFXPanel.java:869)
      at javafx.embed.swing.JFXPanel$$Lambda$18857.29065563.run(Unknown Source:-1)
      at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
      at com.sun.javafx.application.PlatformImpl$$Lambda$18601.12763758.run(Unknown Source:-1)
      at java.security.AccessController.doPrivileged(AccessController.java:-1)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
      at com.sun.javafx.application.PlatformImpl$$Lambda$18598.18016287.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$145(WinApplication.java:101)
      at com.sun.glass.ui.win.WinApplication$$Lambda$18587.12630745.run(Unknown Source:-1)
      at java.lang.Thread.run(Thread.java:745)

      This issue has already been raised as JMY-284, but that appears to be the wrong project for issues like this.

      Note also that this defect was not present in JDK 1.8.0_31.

            ant Anton Tarasov (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: