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

NullPointer in InputMethod components in JFXPanel

    XMLWordPrintable

Details

    • generic
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      JavaFX 17.0.1
      JDK 11.0.7


      A DESCRIPTION OF THE PROBLEM :
      The usage of InputMethod components in JFXPanel is not properly synchronized.
      They are used simultaneously by both the JavaFX and AWT threads.
      This leads to a NullPointerException if the AWT thread accesses them while the Node is no longer in the scene.

      java.lang.NullPointerException: null
      at javafx.scene.control.skin.TextInputControlSkin$6.getTextLocation(TextInputControlSkin.java:308)
      at javafx.scene.Scene$InputMethodRequestsDelegate.getTextLocation(Scene.java:4176)
      at javafx.embed.swing.InputMethodSupport$InputMethodRequestsAdapter.getTextLocation(InputMethodSupport.java:61)
      at sun.awt.im.InputMethodContext.getTextLocation(InputMethodContext.java:278)
      at sun.awt.windows.WInputMethod$1.run(WInputMethod.java:616)
      at java.awt.event.InvocationEvent.dispatch$$$capture(InvocationEvent.java:313)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
      at java.awt.EventQueue$4.run(EventQueue.java:721)
      at java.awt.EventQueue$4.run(EventQueue.java:715)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
      at java.awt.EventQueue$5.run(EventQueue.java:745)
      at java.awt.EventQueue$5.run(EventQueue.java:743)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Start the sample
      2. Click into 'JavaFx TextField' TextField
      3. Focus an window of another application
      4. Focus the sample window
      5. Make the window small so that 'JavaFx TextField' TextField disappears and make it bigger again
      6. Repeat step 5


      ---------- BEGIN SOURCE ----------
      import javax.swing.BoxLayout;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.SwingUtilities;

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.TextField;
      import javafx.scene.control.ToolBar;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;

      public class JavaFxInSwing {

          public static void main(String[] args) {
              SwingUtilities.invokeLater(() -> {

                  JPanel panel = new JPanel();
                  panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                  panel.add(new java.awt.TextField("Swing TextField"));

                  final JFXPanel fxPanel = new JFXPanel();
                  panel.add(fxPanel);

                  JFrame frame = new JFrame("Test");
                  frame.add(panel);
                  frame.setSize(300, 200);
                  frame.setVisible(true);
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                  Platform.runLater(() -> {
                      ToolBar toolBar = new ToolBar();
                      toolBar.getItems().addAll(
                              new Label("JavaFx Label"),
                              new TextField("JavaFx TextField")
                      );
                      fxPanel.setScene(new Scene(new VBox(toolBar), Color.ALICEBLUE));
                  });

              });
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              psadhukhan Prasanta Sadhukhan
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: