RFR: 5080391: ArrayIndexOutOfBounds during "undo" of Right-to-Left text insert [v2]

Prasanta Sadhukhan psadhukhan at openjdk.org
Fri Oct 7 09:05:35 UTC 2022


On Mon, 3 Oct 2022 11:20:17 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Test fix
>
> src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java line 958:
> 
>> 956:                 int index = bidiRoot.getElementIndex(p0);
>> 957:                 Element bidiElem = bidiRoot.getElement(index);
>> 958:                 if (bidiElem != null && bidiElem.getEndOffset() >= p1) {
> 
> Is it possible that `bidiElem` is `null`? It should never be. If it is, it is a bug in the code and throwing NPE seems good — it will be the indication of the bug.
> 
> Since the NPE has never been thrown from this code, I'd rather leave it unchanged here.

`getElement()` can return null [here](https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java#L2619) and [here](https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java#L2398)
so it should not be enitrely impossible not to get null, so it should be a ok

> test/jdk/javax/swing/text/AbstractDocument/TestUndoError.java line 39:
> 
>> 37: import javax.swing.undo.UndoManager;
>> 38: 
>> 39: public class TestUndoError {
> 
> `TestUndoInsertArabicText`? It's more specific this way.

ok

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

PR: https://git.openjdk.org/jdk/pull/10446



More information about the client-libs-dev mailing list