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

[TextField] IOOBE on setting text with control characters that replaces existing text

    XMLWordPrintable

Details

    • b07

    Backports

      Description

        Related to the fixed issue JDK-8212102, when setting directly text with control characters an IOOBE is thrown.

        Running the attached test causes:

        Exception in thread "JavaFX Application Thread" java.lang.StringIndexOutOfBoundsException: begin 8, end 8, length 0
                at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4601)
                at java.base/java.lang.String.substring(String.java:2704)
                at javafx.controls@21-ea/javafx.scene.control.TextInputControl.updateSelectedText(TextInputControl.java:184)
                at javafx.controls@21-ea/javafx.scene.control.TextInputControl.replaceText(TextInputControl.java:1272)
                at javafx.controls@21-ea/javafx.scene.control.TextInputControl.filterAndSet(TextInputControl.java:1228)
                at javafx.controls@21-ea/javafx.scene.control.TextInputControl$TextProperty.doSet(TextInputControl.java:1479)
                at javafx.controls@21-ea/javafx.scene.control.TextInputControl$TextProperty.set(TextInputControl.java:1392)
                at javafx.controls@21-ea/javafx.scene.control.TextInputControl.setText(TextInputControl.java:360)

        The issue can be reproduced when:
        - the new text consist only of control characters like "\n" or "\t\n",
        - and the existing text has a length greater than the new text.

        The same workaround provided in JDK-8212102 (use of a TextFormatter) prevents the issue.

        JavaFX versions 11.0.2 to 11.0.18, 12 until 15-ea-7, work fine.

        JavaFX versions 15-ea-8 to 15, 16, 17 to 17.0.6, 18, 19, 20-ea, 21-ea, head, fail.

        So it seems the fix for the issue JDK-8176270 caused a regression (that is when TextInputControl::updateSelectedText was added), probably by removing these lines in https://github.com/effad/jfx/blob/master/modules/javafx.controls/src/main/java/javafx/scene/control/TextInputControl.java#L183:

            int start = sel.getStart();
            int end = sel.getEnd();
        - int length = txt.length();
        - if (end > start + length) end = length;
        - if (start > length-1) start = end = 0;
            selectedText.set(txt.substring(start, end));

        Bringing them back seems to solve the issue.

        Attachments

          Issue Links

            Activity

              People

                jpereda Jose Pereda
                jpereda Jose Pereda
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: