RFR: JDK-8353755 : Add a helper method to Util - findComponent() [v3]

Alexey Ivanov aivanov at openjdk.org
Tue Nov 4 13:44:54 UTC 2025


On Mon, 3 Nov 2025 21:56:44 GMT, Harshitha Onkar <honkar at openjdk.org> wrote:

>> `findComponent(final Container container, final Predicate<Component> predicate)` is a useful utility method and thus added to` javax/swing/regtesthelpers/Util.java` instead of having redundant code in tests. It can be used to find a component by label name.
>> 
>> PS: Existing `Util.findSubComponent()` finds component by class name but `findComponent()` can be used to search for a particular component by label name/title when there are multiple subcomponents of same type by applying a predicate logic.
>
> Harshitha Onkar has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Review changes: EDT check

Changes requested by aivanov (Reviewer).

test/jdk/javax/swing/JFileChooser/FileSizeCheck.java line 234:

> 232:         Component result = Util.findComponent(container,
> 233:                                          c -> c instanceof JToggleButton button
> 234:                                               && "Details".equals(button.getToolTipText()));

Suggestion:

        Component result = Util.findComponent(container,
                c -> c instanceof JToggleButton button
                     && "Details".equals(button.getToolTipText()));

Let's not touch the indentation of the second parameter. [The comment below](https://github.com/openjdk/jdk/pull/27944/files#r2461135990) is marked as resolved but it's not resolved. This is what I meant.

That is, only `Util.` is added, only one line of the `findDetailsButton` method changes compared to master.

test/jdk/javax/swing/JFileChooser/bug4759934.java line 74:

> 72:             robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK);
> 73:             robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK);
> 74:             robot.delay(500);

All the clicks above are to click a button… Should we replace these clicks with programmatic clicks?

However, I'd like to ensure the updated test still reproduces the original bug. Updating this test could better pull out into its own issue. (Yes, I remember that this refactoring comes from an internal comment I made when `javax/swing/JFileChooser/bug4759934.java` was open-sourced.)

test/jdk/javax/swing/regtesthelpers/Util.java line 169:

> 167: 
> 168:     private static Component findComponentImpl(final Container container,
> 169:                                           final Predicate<Component> predicate) {

Suggestion:

    private static Component findComponentImpl(final Container container,
                                               final Predicate<Component> predicate) {

Align the second wrapped parameter.

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

PR Review: https://git.openjdk.org/jdk/pull/27944#pullrequestreview-3416463764
PR Review Comment: https://git.openjdk.org/jdk/pull/27944#discussion_r2490559501
PR Review Comment: https://git.openjdk.org/jdk/pull/27944#discussion_r2490547507
PR Review Comment: https://git.openjdk.org/jdk/pull/27944#discussion_r2490517210


More information about the client-libs-dev mailing list