JDK-8289705 : Handle the case where IExtractIconW::Extract returns S_FALSE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 17,18,19,20
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows
  • Submitted: 2022-07-04
  • Updated: 2022-12-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21Unresolved
Related Reports
Relates :  
Relates :  
Description
The documentation for IExtractIconW::Extract [1] mentions the method may return S_FALSE in which case the icon extraction should be performed by the application.

This case is not handled in Java_sun_awt_shell_Win32ShellFolder2_extractIcon [2].


The suggestion in the article [3] is to use SH­Def­Extract­Icon [4]:

HICON hico;
if (SHDefExtractIcon(TEXT("C:\\Windows\\Explorer.exe"),
                     1, 0, &hico, NULL, 48) == S_OK) {
  DrawIconEx(pps->hdc, 0, 0, hico, 0, 0, 0, NULL, DI_NORMAL);
  DestroyIcon(hico);
}


References:
[1] https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-iextracticonw-extract
[2] https://github.com/openjdk/jdk/blob/94127f43a4a28a89094fa93cd1da49763134f9db/src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp#L986
[3] https://devblogs.microsoft.com/oldnewthing/20140501-00/?p=1103
[4] https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shdefextracticonw

The issue was raised in the code review for JDK-8282526:
[5] https://github.com/openjdk/jdk/pull/7805#discussion_r893306463
[6] https://github.com/openjdk/jdk/pull/7805#discussion_r893275672
Comments
The fact that S_FALSE return value is not handled, could be the reason for this behaviour: “Because for some files - and we can not predict which files these are - function will always return set of 16×16 and 32×32 icons - no matter what we request. For the icons that return proper sizes we do request exact sizes and use them.” https://github.com/openjdk/jdk/pull/7805#discussion_r888614815
04-07-2022