From 4382249baf8464f604649209470f67dd8e31c42e Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Sat, 17 Jul 2021 14:50:49 +0200 Subject: [PATCH] Menu: Safely check type of 'checkIconFactory' factory property As the type can only mismatch when darklaf is being uninstalled we don't care what happens in this case. Simply don't crash. Moreover this only happens on windows where the window decorations may change the component hierarchy during uninstallation to return the menu bar to the root pane. Currently we don't make use of this property at all, but to keep the implementation close to the swing internal one we keep the method for now. Relates to #234 --- .../java/com/intellij/util/ui/MenuItemLayoutHelper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/intellij/util/ui/MenuItemLayoutHelper.java b/core/src/main/java/com/intellij/util/ui/MenuItemLayoutHelper.java index 3f53b827..0bfc7825 100644 --- a/core/src/main/java/com/intellij/util/ui/MenuItemLayoutHelper.java +++ b/core/src/main/java/com/intellij/util/ui/MenuItemLayoutHelper.java @@ -45,6 +45,8 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.text.View; +import com.github.weisj.darklaf.util.Types; + @SuppressWarnings("unused") public class MenuItemLayoutHelper { public static final StringUIClientPropertyKey MAX_ARROW_WIDTH = new StringUIClientPropertyKey("maxArrowWidth"); @@ -177,13 +179,12 @@ public class MenuItemLayoutHelper { private Icon getIcon(String propertyPrefix) { Icon icon = null; - MenuItemCheckIconFactory iconFactory = - (MenuItemCheckIconFactory) UIManager.get(propertyPrefix + ".checkIconFactory"); + MenuItemCheckIconFactory iconFactory = Types.safeCast( + UIManager.get(propertyPrefix + ".checkIconFactory"), MenuItemCheckIconFactory.class); if (!this.isColumnLayout || !this.useCheckAndArrow || iconFactory == null || !iconFactory.isCompatible(this.checkIcon, propertyPrefix)) { icon = this.mi.getIcon(); } - return icon; }