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

Threading issues typing in FX TextField when focus regained after parent JFrame loses focus

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_161"
      Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
      Java HotSpot(TM) Client VM (build 25.161-b12, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 10 Pro

      A DESCRIPTION OF THE PROBLEM :
      Multiple exceptions are getting thrown when attempting to type into a JavaFX TextField when combined with JFXPanel and JInternalFrame if the user clicks out of the parent JFrame then back in to continue typing. Sometimes the text doubles (i.e. type "test" and "testtest" displays).

      REGRESSION. Last worked in version 8u151

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) Client VM (build 25.151-b12, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run SwingFXTest
      Select Test Menu > Test Item
      Click the text field
      Click outside of the window
      Click the text field again
      Start typing

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The characters typed are displayed in the field and no exceptions are thrown.
      ACTUAL -
      The characters doubled and exceptions were thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "JavaFX Application Thread" java.lang.ArrayIndexOutOfBoundsException: 0
      at com.sun.javafx.text.PrismTextLayout.getCaretShape(PrismTextLayout.java:365)
      at javafx.scene.text.Text$TextAttribute$11.computeValue(Text.java:1787)
      at javafx.scene.text.Text$TextAttribute$11.computeValue(Text.java:1777)
      at javafx.beans.binding.ObjectBinding.get(ObjectBinding.java:153)
      at javafx.beans.binding.ObjectExpression.getValue(ObjectExpression.java:50)
      at javafx.beans.property.ObjectPropertyBase.get(ObjectPropertyBase.java:132)
      at com.sun.javafx.scene.control.skin.TextFieldSkin.lambda$new$198(TextFieldSkin.java:233)
      at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
      at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
      at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
      at javafx.beans.property.ObjectPropertyBase.access$000(ObjectPropertyBase.java:51)
      at javafx.beans.property.ObjectPropertyBase$Listener.invalidated(ObjectPropertyBase.java:233)
      at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
      at javafx.beans.binding.ObjectBinding.invalidate(ObjectBinding.java:172)
      at javafx.scene.text.Text.impl_geomChanged(Text.java:769)
      at javafx.scene.text.Text.needsTextLayout(Text.java:194)
      at javafx.scene.text.Text.needsFullTextLayout(Text.java:189)
      at javafx.scene.text.Text.access$200(Text.java:95)
      at javafx.scene.text.Text$2.invalidated(Text.java:389)
      at javafx.beans.property.StringPropertyBase.markInvalid(StringPropertyBase.java:109)
      at javafx.beans.property.StringPropertyBase.access$000(StringPropertyBase.java:49)
      at javafx.beans.property.StringPropertyBase$Listener.invalidated(StringPropertyBase.java:230)
      at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
      at javafx.beans.binding.StringBinding.invalidate(StringBinding.java:171)
      at com.sun.javafx.binding.BindingHelperObserver.invalidated(BindingHelperObserver.java:51)
      at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
      at javafx.scene.control.TextInputControl$TextProperty.fireValueChangedEvent(TextInputControl.java:1389)
      at javafx.scene.control.TextInputControl$TextProperty.markInvalid(TextInputControl.java:1393)
      at javafx.scene.control.TextInputControl$TextProperty.controlContentHasChanged(TextInputControl.java:1332)
      at javafx.scene.control.TextInputControl$TextProperty.access$1600(TextInputControl.java:1300)
      at javafx.scene.control.TextInputControl.lambda$new$162(TextInputControl.java:139)
      at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:137)
      at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
      at javafx.scene.control.TextField$TextFieldContent.insert(TextField.java:87)
      at javafx.scene.control.TextInputControl.replaceText(TextInputControl.java:1204)
      at javafx.scene.control.TextInputControl.updateContent(TextInputControl.java:556)
      at javafx.scene.control.TextInputControl.replaceText(TextInputControl.java:548)
      at com.sun.javafx.scene.control.skin.TextFieldSkin.replaceText(TextFieldSkin.java:576)
      at com.sun.javafx.scene.control.behavior.TextFieldBehavior.replaceText(TextFieldBehavior.java:202)
      at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.defaultKeyTyped(TextInputControlBehavior.java:238)
      at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:139)
      at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:218)
      at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callActionForEvent(TextInputControlBehavior.java:127)
      at com.sun.javafx.scene.control.behavior.BehaviorBase.lambda$new$74(BehaviorBase.java:135)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Scene$KeyHandler.process(Scene.java:3964)
      at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3910)
      at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040)
      at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2501)
      at com.sun.javafx.tk.quantum.EmbeddedScene.lambda$null$299(EmbeddedScene.java:310)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.EmbeddedScene.lambda$keyEvent$300(EmbeddedScene.java:296)
      at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
      at java.lang.Thread.run(Thread.java:748)
      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at com.sun.javafx.text.PrismTextLayout.layout(PrismTextLayout.java:1209)
      at com.sun.javafx.text.PrismTextLayout.ensureLayout(PrismTextLayout.java:223)
      at com.sun.javafx.text.PrismTextLayout.getBounds(PrismTextLayout.java:246)
      at javafx.scene.text.Text.getLogicalBounds(Text.java:358)
      at javafx.scene.text.Text.getYRendering(Text.java:1069)
      at javafx.scene.text.Text.getRange(Text.java:1012)
      at javafx.scene.text.Text.impl_getRangeShape(Text.java:1027)
      at com.sun.javafx.scene.control.skin.TextFieldSkin.getCharacterBounds(TextFieldSkin.java:676)
      at com.sun.javafx.scene.control.skin.TextInputControlSkin$11.getTextLocation(TextInputControlSkin.java:385)
      at javafx.scene.Scene$InputMethodRequestsDelegate.getTextLocation(Scene.java:4011)
      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:588)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
      at java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.awt.EventQueue$3.run(EventQueue.java:709)
      at java.awt.EventQueue$3.run(EventQueue.java:703)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
      at java.awt.EventQueue$4.run(EventQueue.java:731)
      at java.awt.EventQueue$4.run(EventQueue.java:729)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
      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)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JDesktopPane;
      import javax.swing.JFrame;
      import javax.swing.JInternalFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.SwingUtilities;
      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;

      public class SwingFXTest {

        public static void main(String[] args) {
          SwingUtilities.invokeLater(() -> {
            new SwingFXTest().initAndShowGUI();
          });
        }

        private void initAndShowGUI() {
          JFrame frame = new JFrame("Test 8u161");
          JDesktopPane desktopPane = new JDesktopPane();
          JMenuBar menuBar = new JMenuBar();
          JMenu menu = new JMenu("Test Menu");
          menuBar.add(menu);
          JMenuItem menuItem = new JMenuItem("Test Item");
          menuItem.addActionListener(e -> {
            desktopPane.add(createInternalFrame());
          });
          menu.add(menuItem);
          frame.setJMenuBar(menuBar);
          frame.setContentPane(desktopPane);
          frame.setSize(600, 600);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        private JInternalFrame createInternalFrame() {
          JInternalFrame internalFrame = new JInternalFrame();
          internalFrame.setVisible(true);
          internalFrame.setResizable(true);
          internalFrame.setSize(200, 200);
          final JFXPanel fxPanel = new JFXPanel();
          internalFrame.setContentPane(fxPanel);
          Platform.runLater(() -> initFX(fxPanel));
          return internalFrame;
        }

        private void initFX(JFXPanel fxPanel) {
          TextField field = new TextField();
          Group root = new Group(field);
          Scene scene = new Scene(root);
          fxPanel.setScene(scene);
        }

      }

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

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

              Created:
              Updated:
              Resolved: