RFR: 8286663: Resolve IDE warnings in WTrayIconPeer and SystemTray

Phil Race prr at openjdk.java.net
Mon May 23 17:21:59 UTC 2022


On Mon, 23 May 2022 16:43:05 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

> **WTrayIconPeer**: removed duplicate call to `popupParent.dispose()` that might cause NPE (it looks `popupParent` cannot be `null`); organised imports.
> 
> **SystemTray**: removed redundant initialisers; replaced sized array with empty array in `toArray` call; dropped `newValue != null` chained with `equals`.

src/java.desktop/share/classes/java/awt/SystemTray.java line 349:

> 347:         if (icons != null) {
> 348:             return icons.toArray(new TrayIcon[0]);
> 349:         }

Actually, the old code is more efficient than your new code.
Per the spec https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Vector.html#toArray(T%5B%5D)
Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array. If the Vector fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this Vector.

So your new code allocates one more array than the old code.

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

PR: https://git.openjdk.java.net/jdk/pull/8850



More information about the client-libs-dev mailing list