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

[TextField] IOOBE on paste/replace text with control characters

XMLWordPrintable

    • b02
    • x86_64
    • generic

        ADDITIONAL SYSTEM INFORMATION :
        CPU: x64
        OS: Windows 10 Enterprise
        Java: openjdk-11+28

        A DESCRIPTION OF THE PROBLEM :
        When a single tab or newline symbol or an arbitrary combination of those is pasted from the clipboard into a javafx.scene.control.TextField, an exception is thrown and the textfield seems not to be usable afterwards.

        In contrast, pasting a string that contains regular alphabetic characters interspersed with tabs and newlines like this:
        "\r\n123\t456\r\n789\t"
        will behave well, and when pasted into the textfield will be trimmed to:
        "123456789"

        So I would expect that:
        "\r\n"
        to be trimmed to the empty string:
        ""

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Copy a single tab or newline symbol from any text editor to the clipboard.
        2. Start the test case application provided with this bug report.
        3. Type something into the first textfield, e.g. "12345".
        4. `Tab` away to the second textfield.
        5. `Tab`back to the first textfield. Make sure that the whole text is selected.
        6. Now paste the tab or newline symbol from the clipboard into the first textfield.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        No exception is thrown and the textfield is still usable. The texfield is empty after pasting just tab or newline symbols.
        ACTUAL -
        A StringIndexOutOfBoundsException is thrown and the textfield is no longer usable.

        ---------- BEGIN STACKTRACE ----------
        Exception in thread "JavaFX Application Thread" java.lang.StringIndexOutOfBoundsException: start 0, end 5, length 0
        at java.base/java.lang.AbstractStringBuilder.checkRangeSIOOBE(AbstractStringBuilder.java:1721)
        at java.base/java.lang.AbstractStringBuilder.substring(AbstractStringBuilder.java:1014)
        at java.base/java.lang.StringBuilder.substring(StringBuilder.java:85)
        at javafx.controls/javafx.scene.control.TextField$TextFieldContent.get(TextField.java:79)
        at javafx.controls/javafx.scene.control.TextInputControl.getText(TextInputControl.java:464)
        at javafx.controls/javafx.scene.control.TextInputControl.updateContent(TextInputControl.java:567)
        at javafx.controls/javafx.scene.control.TextInputControl.replaceText(TextInputControl.java:558)
        at javafx.controls/javafx.scene.control.TextInputControl.replaceText(TextInputControl.java:520)
        at javafx.controls/javafx.scene.control.TextInputControl.replaceSelection(TextInputControl.java:1124)
        at javafx.controls/javafx.scene.control.TextInputControl.paste(TextInputControl.java:658)
        at javafx.controls/com.sun.javafx.scene.control.behavior.TextInputControlBehavior.paste(TextInputControlBehavior.java:528)
        at javafx.controls/com.sun.javafx.scene.control.behavior.TextInputControlBehavior.lambda$new$20(TextInputControlBehavior.java:159)
        at javafx.controls/com.sun.javafx.scene.control.behavior.TextInputControlBehavior.lambda$keyMapping$62(TextInputControlBehavior.java:330)
        at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
        at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
        at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
        at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
        at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
        at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4058)
        at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1500(Scene.java:4004)
        at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2121)
        at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2595)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
        at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
        at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
        at java.base/java.lang.Thread.run(Thread.java:834)
        ---------- END STACKTRACE ----------

        ---------- BEGIN SOURCE ----------
        import javafx.application.Application;
        import javafx.scene.Scene;
        import javafx.scene.control.TextField;
        import javafx.scene.layout.Pane;
        import javafx.scene.layout.VBox;
        import javafx.stage.Stage;

        public class DebuggingJavaFXTextField extends Application {

          @Override
          public void start(final Stage primaryStage) {
            final Pane root = new VBox();
            root.getChildren().addAll(new TextField(), new TextField());
            primaryStage.setScene(new Scene(root, 600, 400));
            primaryStage.show();
          }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        I found a workaround on Stackoverflow, that is setting a TextFormatter which simply filters all tabs and newlines to:
        https://stackoverflow.com/questions/36009368/breaking-javafx-when-tab-character-is-pasted-into-textfield/36021504

        However, for a Windows machine I had to filter out "\r" as well, so I had to change the code with the actual text manipulation to:
        text.replaceAll("[\t\r\n]", "")

        FREQUENCY : always


              arapte Ambarish Rapte
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: