On Wed, 21 Jun 2023 08:56:37 GMT, Abhishek Kumar <abhis...@openjdk.org> wrote:
>> 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. I tend to agree⦠there are now two children; if the condition in `getAccessibleChild` fails, it returns `null`. Nothing has changed, there's a possibility that it would return `null`. Yet it shouldn't because both editor and button implement `Accessible`. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14497#discussion_r1246631766