RFR: JDK-8344907 : NullPointerException in Win32ShellFolder2.getSystemIcon when "icon" is null

Alexey Ivanov aivanov at openjdk.org
Tue Dec 17 14:47:37 UTC 2024


On Tue, 17 Dec 2024 04:01:18 GMT, Alexander Zuev <kizune at openjdk.org> 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 1203:
> 
>> 1201:      */
>> 1202:     static Image getSystemIcon(SystemIcon iconType) {
>> 1203:         long hIcon = getSystemIcon(iconType.getIconID());
> 
> What is hIcon value here? If it is 0 we can simply add the same condition as in the getShell32Icon and avoid all the makeIcon and disposeIcon calls. Or we have a valid hIcon code but makeIcon is unable to construct an icon for it?

Yes, I think you should add the condition `if (hIcon != 0)` before calling `makeIcon(hIcon)`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22776#discussion_r1888597821


More information about the client-libs-dev mailing list