From a284b69a1e75df82128b11e44863200e67303d92 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 11 Nov 2021 12:35:16 +0100 Subject: [PATCH] FileChooser: workaround for crash on Windows with Java 17 32bit (issue #403) (cherry picked from commits 44d8545c09f84257b171057343287fd6cd752402 and 33b25c11294ab71297f9b66b1f0a19b84d9f66a2) --- CHANGELOG.md | 2 ++ .../com/formdev/flatlaf/ui/FlatFileChooserUI.java | 12 ++++++++++-- .../java/com/formdev/flatlaf/util/SystemInfo.java | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee7b8f26..abd19639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ FlatLaf Change Log `TextComponent.selectAllOnFocusPolicy` is `once` (the default) or `always`. (issue #395) - Linux: Fixed NPE when using `java.awt.TrayIcon`. (issue #405) +- FileChooser: Workaround for crash on Windows with Java 17 32-bit (disabled + Windows icons). Java 17 64-bit is not affected. (issue #403) ## 1.6.1 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFileChooserUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFileChooserUI.java index 061f0c75..9ed9e909 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFileChooserUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatFileChooserUI.java @@ -262,12 +262,20 @@ public class FlatFileChooserUI @Override public FileView getFileView( JFileChooser fc ) { - return fileView; + return doNotUseSystemIcons() ? super.getFileView( fc ) : fileView; } @Override public void clearIconCache() { - fileView.clearIconCache(); + if( doNotUseSystemIcons() ) + super.clearIconCache(); + else + fileView.clearIconCache(); + } + + private boolean doNotUseSystemIcons() { + // Java 17 32bit craches on Windows when using system icons + return SystemInfo.isWindows && SystemInfo.isJava_17_orLater && !SystemInfo.isX86_64; } //---- class FlatFileView ------------------------------------------------- diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java index 305d4ed6..eceecf9b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java @@ -46,6 +46,7 @@ public class SystemInfo public static final boolean isJava_9_orLater; public static final boolean isJava_11_orLater; public static final boolean isJava_15_orLater; + /** @since 2 */ public static final boolean isJava_17_orLater; // Java VMs public static final boolean isJetBrainsJVM; @@ -82,6 +83,7 @@ public class SystemInfo isJava_9_orLater = (javaVersion >= toVersion( 9, 0, 0, 0 )); isJava_11_orLater = (javaVersion >= toVersion( 11, 0, 0, 0 )); isJava_15_orLater = (javaVersion >= toVersion( 15, 0, 0, 0 )); + isJava_17_orLater = (javaVersion >= toVersion( 17, 0, 0, 0 )); // Java VMs isJetBrainsJVM = System.getProperty( "java.vm.vendor", "Unknown" )