From d10bcfc72fda6156ab104e1c52835eeef4282b2c Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Tue, 12 Oct 2021 23:50:45 +0200 Subject: [PATCH] Theme Editor: fixed StackOverflowError when adding "defaultFont" key to properties file --- .../flatlaf/themeeditor/FlatThemePreview.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePreview.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePreview.java index 5872f8ad..2225e10b 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePreview.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemePreview.java @@ -49,6 +49,7 @@ class FlatThemePreview private final Map lazyValueCache = new WeakHashMap<>(); private int runWithUIDefaultsGetterLevel; + private boolean inGetDefaultFont; FlatThemePreview( FlatSyntaxTextArea textArea ) { this.textArea = textArea; @@ -158,6 +159,11 @@ class FlatThemePreview } Object getUIDefaultProperty( Object key ) { + // avoid StackOverflowError because "defaultFont" value is an active value + // that itself uses UIManager.getFont( "defaultFont" ) to get base font + if( inGetDefaultFont ) + return null; + if( !(key instanceof String) ) return null; @@ -167,12 +173,18 @@ class FlatThemePreview return null; Object value = textArea.propertiesSupport.getParsedProperty( (String) key ); - if( value instanceof LazyValue ) { - value = lazyValueCache.computeIfAbsent( (LazyValue) value, k -> { - return k.createValue( null ); - } ); - } else if( value instanceof ActiveValue ) - value = ((ActiveValue)value).createValue( null ); + + inGetDefaultFont = "defaultFont".equals( key ); + try { + if( value instanceof LazyValue ) { + value = lazyValueCache.computeIfAbsent( (LazyValue) value, k -> { + return k.createValue( null ); + } ); + } else if( value instanceof ActiveValue ) + value = ((ActiveValue)value).createValue( null ); + } finally { + inGetDefaultFont = false; + } // System.out.println( key + " = " + value ); @@ -183,7 +195,7 @@ class FlatThemePreview // E.g. FlatLightLaf defines Button.focusedBackground, but in FlatDarkLaf // it is not defined. Without this code, the preview for FlatDarkLaf would use // Button.focusedBackground from FlatLightLaf if FlatLightLaf is the current application Laf. - if( value == null && FlatThemePropertiesBaseManager.getDefindedCoreKeys().contains( key ) ) + if( value == null && FlatThemePropertiesBaseManager.getDefindedCoreKeys().contains( key ) && !"defaultFont".equals( key ) ) return FlatLaf.NULL_VALUE; return value;