When I run this simple code snippet of a JavaFX TextField element, I type something into the text field, and then StringIndexOutOfBoundsException is thrown periodically.
versions
JDK: 21.0.0, 21.0.2, 1.8
JavaFX:
`javafx.runtime.version=8.0.65 javafx.runtime.build=b17`
`javafx.version=21 javafx.runtime.version=21+31 javafx.runtime.build=31`
Windows:
`Edition=Windows 11 Pro, Version=23H2`
Error Message
Exception in thread "JavaFX Application Thread" java.lang.StringIndexOutOfBoundsException: Range [1, -2147483648) out of bounds for length 1
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)
at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:112)
at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:349)
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4861)
at java.base/java.lang.String.substring(String.java:2830)
at javafx.graphics@21/com.sun.glass.ui.win.WinTextRangeProvider.GetText(WinTextRangeProvider.java:367)
at javafx.graphics@21/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics@21/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
at java.base/java.lang.Thread.run(Thread.java:1583)
source code
package comp3111.qsproject;
// Java program to create a textfield and add it to stage
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class TextFieldTest extends Application {
// launch the application
public void start(Stage s)
{
// set title for the stage
s.setTitle("creating TextField");
// create a textfield
TextField b = new TextField();
// create a stack pane
StackPane r = new StackPane();
// add textfield
r.getChildren().add(b);
// create a scene
Scene sc = new Scene(r, 200, 200);
// set the scene
s.setScene(sc);
s.show();
}
public static void main(String args[])
{
// launch the application
launch(args);
}
}
This problem was not resolved when I reinstalled my JDK.
ITextRangeProvider::GetText method (uiautomationcore.h)
? – Lazarettocom.sun.glass.ui.win.WinTextRangeProvider
, or in native code that references. – Lopsidedjava.lang.String.checkBoundsBeginEnd
is. Seven levels of method calls and two lambdas just to throw an exception? Given the exception branch is rare, all that code is likely going to be interpreted.... – Sclera