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.
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`
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)
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.
Workaround: Close other running apps.
Update: There is an official issue for this: https://bugs.openjdk.org/browse/JDK-8330462.
At JabRef#11151 it was reported that the DeepL Windows App caused the issue. I tried it on my Windows 10 machine. Having DeepL running: Error appears. DeepL closed: Error gone.
For the others to reproduce:
If you could reproduce (or not), please share details at https://github.com/koppor/jfx/pull/2. It seems that not all persons can reproduce and there could be some specific setups. - I personally fired up a fresh Windows on Azure, created another user login (without (!) admin rights), logged in with that user and could reproduce. The issue does not appear if logged in as administrator!