RFR: 8357226: Remove unnecessary List.indexOf from RepaintManager.removeInvalidComponent
Alexey Ivanov
aivanov at openjdk.org
Mon May 19 12:37:54 UTC 2025
On Tue, 13 May 2025 00:47:09 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> Do you suggest to use `List.indexOf` instead of manual loop?
>> https://github.com/openjdk/jdk/blob/375ac6d446332f0763ce294b200143ff63865cf6/src/java.desktop/share/classes/javax/swing/RepaintManager.java#L366-L371
>>
>> This loop uses `==` comparison, while `List.indexOf` uses `equals()`. It could change semantic
>
> ok, the it is fine as is.
Yet there could be a logical error anyway… `addInvalidComponent` uses identity comparison when adding a component but `removeInvalidComponent` relies on `equals` method to remove a component.
If a component overrides `equals`, it could lead to unpredictable behaviour: a wrong component could be removed.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24845#discussion_r2095611426
More information about the client-libs-dev
mailing list