<AWT Dev> RFR: 6278172: TextComponent.getSelectedText() throws StringIndexOutOfBoundsException

Sergey Bylokhov serb at openjdk.java.net
Sat Nov 7 07:37:03 UTC 2020

The text components are implements as wrappers over the "native" peers. Most of the functionality is provided by the peers not wrappers like TextArea/TextField. The current bug occurs in the TextArea/TextField when the native peer was created yet.

The steps to reproduce:
 1. Sets the long text to the component
 2. Select all text in the component
 3. Sets the short text to the component
 4. Request the selected text -> BOOM

The bug on step 4 occurred because we request a long substring of the short text. To eliminate an exception we have two choices:
 1. Preserve the selection in the setText(), but limit it by the length of the current text.
 2. Resets the selection.

I tried both solutions, the second caused some TCK tests to fail, so I selected the first one.


Commit messages:
 - Merge branch 'master' into JDK-6278172
 - Initial fix

Changes: https://git.openjdk.java.net/jdk/pull/1104/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=1104&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-6278172
  Stats: 119 lines in 2 files changed: 107 ins; 3 del; 9 mod
  Patch: https://git.openjdk.java.net/jdk/pull/1104.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/1104/head:pull/1104

PR: https://git.openjdk.java.net/jdk/pull/1104

More information about the awt-dev mailing list