<Swing Dev> [jdk17] RFR: 8269269: [macos11] SystemIconTest fails with ClassCastException

Sergey Bylokhov serb at openjdk.java.net
Tue Jun 29 23:56:59 UTC 2021


On Tue, 29 Jun 2021 22:10:46 GMT, Alexander Zuev <kizune at openjdk.org> wrote:

> Added check for the icon class type
> Added check if file or folder we are testing against exists and
> accessible
> Removed test from problem list

test/jdk/javax/swing/JFileChooser/FileSystemView/SystemIconTest.java line 75:

> 73:     static void testSystemIcon(File file, boolean implComplete) {
> 74:         int[] sizes = new int[] {16, 32, 48, 64, 128};
> 75:         if (!file.exists() || !file.canRead()) {

If this file is not accessible the "getSystemIcon" should return "null" you can check it here.

test/jdk/javax/swing/JFileChooser/FileSystemView/SystemIconTest.java line 76:

> 74:         int[] sizes = new int[] {16, 32, 48, 64, 128};
> 75:         for (int size : sizes) {
> 76:             ImageIcon icon = (ImageIcon) fsv.getSystemIcon(file, size, size);

Probably we can wrap the  "UIManager.getIcon" in the "ImageIcon"?

test/jdk/javax/swing/JFileChooser/FileSystemView/SystemIconTest.java line 88:

> 86:             }
> 87: 
> 88:             ImageIcon icon = (ImageIcon) i;

One more time would like to highlight that to get the data of the requested image the user need to do one "if" and two "instanceof". Still hope that we can improve this.

    Icon icon = fsv.getSystemIcon(file, width, height);
    if (icon.getIconWidth() != width && icon.getIconHeight() != height) {
        return scaleTheIconInTheSameWayAsBeforeTheFix(icon, width, height);
    } else if (icon instanceof ImageIcon) {
        ImageIcon imageIcon = (ImageIcon) icon;
        if (icon.getImage() instanceof MultiResolutionImage) {
            MultiResolutionImage mri = (MultiResolutionImage) icon.getImage();
            return  mri.getResolutionVariant(width, height);
        } else {
            return imageIcon;
        }
    } else {
        return icon;
    }

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

PR: https://git.openjdk.java.net/jdk17/pull/178


More information about the swing-dev mailing list