JDK-8289756 : Do not always request 16x16 icon
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 20
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows
  • Submitted: 2022-07-05
  • Updated: 2024-01-26
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
When an icon is extracted, 16×16 is always extracted even though it's not used.

This code wasn't part of JDK-8182043, it was removed to address this comment [1].

Yet it proved that small (16×16) isn't always extracted with that approach [2]. JDK-8282526 brings extraction of 16x16 icon back [3][4].

Even though it doesn't seem to add any performance penalty [4], "...there is no performance impact at all from the latest changes...", I think a cleaner way would be extract only one icon.

If the icon size requested is less than 24, set the size to `16 << 16` and extract only the small icon only; otherwise, extract the large icon.

Something like this should work:
            if (size < 24) {
                iconSize = (size << 16);
                hres = pIcon->Extract(szBuf, index, NULL, &hIcon, iconSize);
            } else {
                iconSize = size;
                hres = pIcon->Extract(szBuf, index, &hIcon, NULL, iconSize);
            }

// hIcon is the handle to the icon


References:
[1] https://github.com/openjdk/jdk/pull/380#discussion_r500639220
[2] https://github.com/openjdk/jdk/blob/94127f43a4a28a89094fa93cd1da49763134f9db/src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp#L983-L986
[3] https://github.com/openjdk/jdk/pull/7805#issuecomment-1148010850
[4] https://github.com/openjdk/jdk/blob/3d177fea00efe68e742db91f05f82a692957670c/src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp#L985-L994