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

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

Commit messages:
 - jcheck
 - 8391985: View.getNextVisualPositionFrom can throw NullPointerException

Changes: https://git.openjdk.org/jdk/pull/33049/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=33049&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8391985
  Stats: 77 lines in 2 files changed: 74 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/33049.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/33049/head:pull/33049

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

Reply via email to