On Mon, 19 Jun 2023 12:36:31 GMT, Nikita Provotorov <d...@openjdk.org> wrote:

>> Can you please elaborate more or what logic can be added here?
>
> I mean `getAccessibleChild(..., 1)` can still return null (when both `if`s of 
> `case 1` resolve to false). Let's consider the following code:
> 
> public void doSmthWith(JComponent component, BasicComboBoxUI ui) {
>     if (ui.getAccessibleChildrenCount(component) > 1) {
>         // well, we have at least 2 components, so we can expect to get a 
> valid object below
>         final var ac = ui.getAccessibleChild(component, 1)
>                                   .getAccessibleContext(); // <= possible NPE
>         // ...
>     }
> }
> 
> 
> I think we have to return 1 from `getAccessibleChildrenCount(...)` for the 
> cases when `getAccessibleChild(..., 1)` returns `null`

I think it is not needed to return 1 from `getAccessibleChildrenCount(...)`.  
`getAccessibleChildrenCount(...)` is used to get the exact number of accessible 
child for a component and afterwards `getAccessibleChild(..., index)` method 
can be invoked to get the child.

It should be ok to return null if the switch case condition fails or index 
doesn't match with case statement. Although chances of returning null is very 
unlikely for index 0 and 1.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14497#discussion_r1236653059

Reply via email to