RFR: JDK-8353755 : Add a helper method to Util - findComponent() [v3]
Alexey Ivanov
aivanov at openjdk.org
Tue Nov 4 13:26:53 UTC 2025
On Mon, 3 Nov 2025 21:48:30 GMT, Harshitha Onkar <honkar at openjdk.org> wrote:
>> test/jdk/javax/swing/regtesthelpers/Util.java line 1:
>>
>>> 1: /*
>>
>>> Existing `Util.findSubComponent()` finds component by class name
>>
>> To eliminate code duplication, the existing `findSubComponent` should use the new `findComponent` which is more flexible. Just pass `parent.getClass().getName().contains(className)` as the predicate to the new method.
>
> 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));
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27944#discussion_r2490504845
More information about the client-libs-dev
mailing list