<i18n dev> RFR: 8357224: Avoid redundant WeakHashMap.get in Toolkit.removeAWTEventListener

Alexey Ivanov aivanov at openjdk.org
Mon May 19 12:28:52 UTC 2025


On Mon, 19 May 2025 08:10:42 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

>> src/java.desktop/share/classes/java/awt/Toolkit.java line 1745:
>> 
>>> 1743:         synchronized (this) {
>>> 1744:             SelectiveAWTEventListener selectiveListener =
>>> 1745:                 listener2SelectiveListener.remove(localL);
>> 
>> While analyzing the implementation of this method, I noticed a potential bug at the beginning. Should it instead be:
>> 
>> if (localL == null) {
>>     return;
>> }
>> 
>> ?
>
> Looks like yes. I think it's worth to create a separate issue to fix it.

It doesn't matter, it looks… `localL` is `null` if and only if listener is `null`.

However, I'd put the null-check above the call to `deProxyAWTEventListener` to avoid any confusion.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24692#discussion_r2095589937


More information about the i18n-dev mailing list