On Sat, 31 Oct 2026 06:48:35 GMT, Jeremy Wood <[email protected]> wrote:

> This resolves the NPE reported in 8395930, and it enhances the preexisting 
> test for JDK-8381236 to cover this case.
> 
> The failing use case involves an Accessible object where 
> `axObj.getAccessibleContext() == null`. Having a `null` AccessibleContext is 
> an atypical case, but it is explicitly identified/allowed in the contract for 
> `Accessible.getAccessibleContext()`.
> 
> Prior to [8381236 
> changes](https://github.com/openjdk/jdk/pull/30578/changes), calling 
> CAccessible.getCAccessible(ax) would also fail with a NPE. So in this PR I'm 
> proposing preserving that behavior (and documenting it), and moving the null 
> check to 8381236's new `disposeRecursively` method.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Alternatively, the private `getCAccessible(…)` overload can be given an 
additional parameter controlling whether to return `null` on a `null` return 
from `a.getAccessibleContex()`:

src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessible.java line 60:

> 58: 
> 59:     public static CAccessible getCAccessible(final Accessible a) {
> 60:         return getCAccessible(a, true);

Suggestion:

        return getCAccessible(a, true, false);

src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessible.java line 74:

> 72:     private static CAccessible getCAccessible(final Accessible a, final 
> boolean createIfUndefined) {
> 73:         if (a == null) return null;
> 74:         AccessibleContext context = a.getAccessibleContext();

Suggestion:

    private static CAccessible getCAccessible(final Accessible a, final boolean 
createIfUndefined, final boolean returnNullOnNullContext) {
        if (a == null) return null;
        AccessibleContext context = a.getAccessibleContext();
        if (returnNullOnNullContext && context == null) return null;

src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessible.java line 108:

> 106:                 if (c instanceof Accessible ax &&
> 107:                         ax.getAccessibleContext() != null) {
> 108:                     CAccessible ca = getCAccessible(ax, false);

Suggestion:

                if (c instanceof Accessible ax) {
                    CAccessible ca = getCAccessible(ax, false, true);

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

PR Review: https://git.openjdk.org/jdk/pull/33657#pullrequestreview-5731566458
PR Review Comment: https://git.openjdk.org/jdk/pull/33657#discussion_r4438475224
PR Review Comment: https://git.openjdk.org/jdk/pull/33657#discussion_r4438474356
PR Review Comment: https://git.openjdk.org/jdk/pull/33657#discussion_r4438476941

Reply via email to