Skip to content

8389970: StringIndexOutOfBoundsException when a text containing a mnemonic is removed - #2253

Open
eduardsdv wants to merge 1 commit into
openjdk:masterfrom
eduardsdv:bugfix/JDK-8389970-mnemonic-StringIndexOutOfBoundsException
Open

8389970: StringIndexOutOfBoundsException when a text containing a mnemonic is removed#2253
eduardsdv wants to merge 1 commit into
openjdk:masterfrom
eduardsdv:bugfix/JDK-8389970-mnemonic-StringIndexOutOfBoundsException

Conversation

@eduardsdv

@eduardsdv eduardsdv commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This PR fixes the StringIndexOutOfBoundsException, that occurs when an empty text is set to a Labeled, that previously contained a mnemonic.

The reason for the error is that the updateDisplayedText(double, double), which also updates containsMnemonic flag, was not invoked if the text was empty. The value of this flag was still true but the index of the mnemonic character inside MnemonicInfo had already been updated to -1. This led to the StringIndexOutOfBoundsException in the line 611.

I fixed it by moving the call to updateDisplayedText(double, double) outside the if-clause, so that it is always called when the text is being laid out. This should not affect performance because the method already checks whether recalculation is required. If not, it exits quickly.



Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8389970: StringIndexOutOfBoundsException when a text containing a mnemonic is removed (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/2253/head:pull/2253
$ git checkout pull/2253

Update a local copy of the PR:
$ git checkout pull/2253
$ git pull https://git.openjdk.org/jfx.git pull/2253/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2253

View PR using the GUI difftool:
$ git pr show -t 2253

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/2253.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Aug 7, 2026

Copy link
Copy Markdown

👋 Welcome back eduardsdv! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Aug 7, 2026

Copy link
Copy Markdown

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@eduardsdv eduardsdv changed the title Fix StringIndexOutOfBoundsException 8389970: Fix StringIndexOutOfBoundsException Aug 7, 2026
@openjdk openjdk Bot added the rfr Ready for review label Aug 7, 2026
@eduardsdv eduardsdv changed the title 8389970: Fix StringIndexOutOfBoundsException 8389970: StringIndexOutOfBoundsException when a text containing a mnemonic is removed Aug 7, 2026
@openjdk

openjdk Bot commented Aug 7, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: rfr. This can be overridden with the /reviewers command.

@mlbridge

mlbridge Bot commented Aug 7, 2026

Copy link
Copy Markdown

Webrevs

@andy-goryachev-oracle

Copy link
Copy Markdown
Contributor

Thank you for logging the bug and offering to fix it!
The reproducer works fine with macOS; I'll test it on windows soon.

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good solution.

@andy-goryachev-oracle

Copy link
Copy Markdown
Contributor

as I commented in the ticket, the mnemonic decorations are not visible on macOS so this issue does not occur there. It still needs to be tested on linux.

@arapte could you be the second reviewer please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rfr Ready for review

Development

Successfully merging this pull request may close these issues.

2 participants