-
Bug
-
Resolution: Fixed
-
P3
-
jfx15
-
b07
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8304068 | jfx17.0.7 | Johan Vos | P3 | Resolved | Fixed |
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 inJDK-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 issueJDK-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.
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
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
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.
- backported by
-
JDK-8304068 [TextField] IOOBE on setting text with control characters that replaces existing text
-
- Resolved
-
- relates to
-
JDK-8176270 Adding ChangeListener to TextField.selectedTextProperty causes StringOutOfBoundsException
-
- Resolved
-
- links to
-
Commit openjdk/jfx17u/d045d2b2
-
Commit openjdk/jfx/9df6039a
-
Review openjdk/jfx17u/117
-
Review openjdk/jfx/1043
(1 links to)