StringIndexOutOfBoundException occurs when typing anything into a JavaFX TextField in both JDK21 and JDK8, Windows11
Asked Answered
L

1

14

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.

Lyonnesse answered 16/4 at 5:32 Comment(20)
Not able to reproduce the issue in Java 1.8Disclosure
When running as Admin, the issue disappears, right?Lazaretto
We have the same issue here in a non-minimal-example: github.com/JabRef/jabref/issues/11151Lazaretto
@Super3001: Maybe submit a bug report at bugreport.java.com/bugreport.Lazaretto
I checked github.com/openjdk/jfx/blame/jfx22/modules/javafx.graphics/src/…. Not modified since years. Strange. Did Microsoft mess up with ITextRangeProvider::GetText method (uiautomationcore.h)?Lazaretto
Note that a related code change (github.com/openjdk/jfx/commit/…) is from 2022 - and should not cause an effect two years later.Lazaretto
That code change has some tags where it was released. Seems that this happens from JavaFX 20. - @Super3001: Could you try JavaFX 19?Lazaretto
GluonHQ created a hotfix for LTS customers: github.com/JabRef/jabref/issues/11151#issuecomment-2058566128Lazaretto
Tested this on Mac OS X, JDK 22, JavaFX 22 with no exceptions being generated. This provides more evidence that the issue arises in com.sun.glass.ui.win.WinTextRangeProvider, or in native code that references.Lopsided
I am (currently) unable to compile JavaFX fully. I think, the patch should be github.com/koppor/jfx/pull/2/commits/….Lazaretto
yes, it is the same problem as github.com/JabRef/jabref/issues/11151#issuecomment-2058566128. maybe I should try this hotfix @LazarettoLyonnesse
Created a JBS ticket for this: bugs.openjdk.org/browse/JDK-8330462Jamima
@Lyonnesse We need details about the Windows. Which updates are installed? Which variant of Windows? Locale? Which graphics card driver?Lazaretto
(I am just amazed by how over-engineered java.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
@Sclera In recent Java, I see only one call. See github.com/openjdk/jdk/blob/…. Which line did you look at?Lazaretto
@Lazaretto may I send you screenshots of the details about my Windows?Lyonnesse
@Lyonnesse Sure! You can also comment at github.com/koppor/jfx/pull/2. Think, you find my email adress online? if not --> kopp dev -> gmailLazaretto
@Lazaretto I have commented on GitHub and emailed you more details. hope that it is not too late. Sorry for not being proficient in that.Lyonnesse
Was posting a bit of error as image necessary? It probably should be removed.Aracelis
@Aracelis Okay, I'll take your advice!Lyonnesse
L
5

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:

  1. Go to https://www.deepl.com/en/app/
  2. Download the app
  3. Install the app for the current user
  4. Start the app
  5. Mark some text
  6. Press Ctrl+C+C to check that DeepL really runs
  7. Switch to a JavaFX appp
  8. Enter something in a text field
  9. You should see the exception

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!

Lazaretto answered 17/4 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.