RFR: 8304831: TextFlow.hitTest.insertionIndex incorrect with surrogate pairs [v4]

Phil Race prr at openjdk.org
Fri Jun 2 19:21:17 UTC 2023


On Fri, 2 Jun 2023 18:50:07 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

>> I did note that TextFlow passed null which really looked like a WIP to me but its a separate issue.
>> The exception in 8302511 which is the entire subject of that bug isn't possible if text == null.
>> My point is that if you pass an incorrect charIndex to BreakIterator.following() you'll get the same exception
>> in your copy of that code. So how are you making sure you never do that ?
>
> The exception in 8302511 was likely caused by a prior exception due to null text, which corrupted insertionIndex value in HitInfo.
> 
> The goal of this change is to always compute insertionIndex (an I believe we do it correctly this time).

No, it wasn't due to null text. That is provably impossible.

The exception from JDK-8302511 is as follows (copied from the bug report).

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: offset out of bounds 
at java.base/sun.text.RuleBasedBreakIterator.checkOffset(RuleBasedBreakIterator.java:730) 
at java.base/sun.text.RuleBasedBreakIterator.following(RuleBasedBreakIterator.java:744) 
at javafx.graphics/javafx.scene.text.HitInfo.getInsertionIndex(HitInfo.java:84) 
at javafx.graphics/javafx.scene.text.HitInfo.toString(HitInfo.java:100) 
Look at the code in HitInfo.java referenced in JDK-8302511,  the code at line 84 can only be reached if text != null
..
              if (text != null) {
                    // Skip complex character clusters / ligatures.
                    int next;
                    synchronized(charIterator) {
                        charIterator.setText(text);
                        next = charIterator.following(insertionIndex);   // this is line 84
                    }

...

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/1091#discussion_r1214735858


More information about the openjfx-dev mailing list