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

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


On Tue, 4 Nov 2025 13:22:33 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> Tested by in turn calling findComponent() from findSubComponent() it does not work as expected since the recursive logic to find the component differs for both methods.
>> 
>> Replacing findSubComponent() as below with the latest changes does not work. To verify run javax/swing/JColorChooser/Test7194184.java by replacing the findSubComponent() as below.
>> 
>> 
>>     public static Component findSubComponent(Component parent, String className) {
>>         String parentClassName = parent.getClass().getName();
>> 
>>         if (parentClassName.contains(className)) {
>>             return parent;
>>         }
>>         return findComponent((Container) parent,
>>                                  c -> parent.getClass().getName().contains(className));
>>     }
>
> It fails because the code I proposed is plainly wrong.
> 
> 
>     public static Component findSubComponent(Component parent, String className) {
>         return findComponentImpl((Container) parent,
>                                  c -> c.getClass().getName().contains(className));
>     }

I would even format it like this, wrapping all the chained calls:


    public static Component findSubComponent(Component parent, String className) {
        return findComponentImpl((Container) parent,
                                 c -> c.getClass()
                                       .getName()
                                       .contains(className));
    }

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27944#discussion_r2490509126


More information about the client-libs-dev mailing list