On Tue, 17 Dec 2024 00:03:32 GMT, Harshitha Onkar <[email protected]> wrote:
>> Win32ShellFolder2.getSystemIcon() can result in NPE if icon is null. Sanity
>> null checks have been added.
>>
>>
>> long hIcon = getSystemIcon(iconType.getIconID()); //Can return null
>> Image icon = makeIcon(hIcon); // returns null if the condition (hIcon != 0L
>> && hIcon != -1L) is false
>> if (LARGE_ICON_SIZE != icon.getWidth(null)) { // NullPointerException --
>> icon is null
>>
>>
>> Occurs when Windows is unable to provide a system icon and the code assumes
>> an icon will **always** be returned, but the Windows API makes no such
>> guarantee.
>>
>> getSystemIcon calls LoadIcon (User32.dll). This can return null.
>> https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadicona
>
> src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java line
> 1220:
>
>> 1218: Image icon = makeIcon(hIcon);
>> 1219: if (icon != null && size != icon.getWidth(null)) {
>> 1220: icon = new MultiResolutionIconImage(size, icon);
>
> Although `icon != null` check is not strictly required here due to `hIcon !=
> 0` check, added it as sanity check and to be consistent with other locations
> in Win32ShellFolder2.java where makeIcon() is called (which is followed by a
> null check for the returned icon).
I'd leave it out here. As @azuev-java [notes
above](https://github.com/openjdk/jdk/pull/22776/files#r1887863199), the likely
problem is `hIcon == 0` rather than `makeIcon` returns `null`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22776#discussion_r1888602404