On Fri, 7 Oct 2022 09:01:35 GMT, Prasanta Sadhukhan <psadhuk...@openjdk.org> 
wrote:

> `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

I know it is possible _theoretically_. My point is for a valid offset in the 
document, this particular line must _never_ return `null`. If it does, the 
element tree is invalid. As such, we should rather catch the case of bad bidi 
element tree by throwing NPE rather than pretending nothing bad happened.

`BidiRootElement` is a `BranchElement`: 
https://github.com/openjdk/jdk/blob/096bca4a9c5e8ac2668dd965df92153ea1d80add/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java#L2700-L2713

And 
[`BranchElement.getElementIndex`](https://github.com/openjdk/jdk/blob/096bca4a9c5e8ac2668dd965df92153ea1d80add/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java#L2416-L2474)
 always returns a *valid* index.

So, I am against adding the `null`-check. It is not necessary here.

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

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

Reply via email to