On Thu, 24 Sep 2026 06:21:44 GMT, Prasanta Sadhukhan <[email protected]> wrote:
> `View.getNextVisualPositionFrom `could throw a NullPointerException when > asked to navigate NORTH or SOUTH while the view has no JTextComponent > container > > Although the method initially handled a null container before retrieving the > caret, > it later dereferenced the same container calling `modelToView` and passed it > to vertical-navigation methods `getPositionAbove`/`getPositionBelow `causing > NPE. > > The fix verifies that the container is a JTextComponent before performing > vertical navigation. If no suitable text component is available, the method > returns -1 (since -1 is already established as “not computable/no visual > position” as per the `Utilities.getPositionAbove/Below `spec) > https://github.com/openjdk/jdk/blob/2365ecc5fd83cf27c6c55aaca5aa6bad6ae9dbbf/src/java.desktop/share/classes/javax/swing/text/Utilities.java#L748-L749 > indicating that the next visual position cannot be computed. The fix also > avoids a potential ClassCastException when the container is not a text > component. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). test/jdk/javax/swing/text/View/TestViewVisualPostion.java line 28: > 26: * @bug 8391985 > 27: * @summary View.getNextVisualPositionFrom can throw NullPointerException > 28: * @run main TestViewVisualPostion I don' t think that's the spelling you meant test/jdk/javax/swing/text/View/TestViewVisualPostion.java line 30: > 28: * @run main TestViewVisualPostion > 29: */ > 30: This test doesn't even compile ... ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/33049#discussion_r4096515115 PR Review Comment: https://git.openjdk.org/jdk/pull/33049#discussion_r4096508309
