From d6660e11858e2619079144cca33a2c0357a0b71f Mon Sep 17 00:00:00 2001 From: Danil Sokolov Date: Sat, 21 Nov 2026 16:50:36 +0000 Subject: [PATCH] Fall back to default base theme for custom theme Under a look and feel without a plaf mapping, UIFactory.createTheme had no base theme and a custom theme that left out a UI threw NullPointerException. Fixes #35 --- .../java/org/flexdock/plaf/theme/UIFactory.java | 4 ++++ .../flexdock/test/view/ThemeConfigurationTest.java | 14 +++++--------- release-notes.txt | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/flexdock-view/src/main/java/org/flexdock/plaf/theme/UIFactory.java b/flexdock-view/src/main/java/org/flexdock/plaf/theme/UIFactory.java index 2db265d5..abb4fc27 100644 --- a/flexdock-view/src/main/java/org/flexdock/plaf/theme/UIFactory.java +++ b/flexdock-view/src/main/java/org/flexdock/plaf/theme/UIFactory.java @@ -203,6 +203,10 @@ public static Theme createTheme(Properties p) { } Theme base = getTheme(PlafManager.getSystemThemeName()); + if(base==null) { + // look and feel without a mapping + base = getTheme(DEFAULT); + } ViewUI view = getViewUI(p); if(view==null) { diff --git a/flexdock-view/src/test/java/org/flexdock/test/view/ThemeConfigurationTest.java b/flexdock-view/src/test/java/org/flexdock/test/view/ThemeConfigurationTest.java index 014558c3..0506f97b 100644 --- a/flexdock-view/src/test/java/org/flexdock/test/view/ThemeConfigurationTest.java +++ b/flexdock-view/src/test/java/org/flexdock/test/view/ThemeConfigurationTest.java @@ -8,7 +8,7 @@ import javax.swing.LookAndFeel; import javax.swing.UIManager; -import javax.swing.plaf.nimbus.NimbusLookAndFeel; +import javax.swing.plaf.metal.MetalLookAndFeel; import java.util.Properties; import static org.junit.jupiter.api.Assertions.*; @@ -68,17 +68,13 @@ void testRemovedCustomThemeIsReturnedOnce() { assertNull(PlafManager.removeCustomTheme(THEME_NAME)); } - // Known bug (https://github.com/opencollab/flexdock/issues/35): - // under a look and feel without a mapping (e.g. Aqua on macOS, Nimbus) - // there is no base theme, so a custom theme with missing UIs throws an NPE in - // UIFactory.createTheme. Once fixed, assertThrows fails: check that the theme is created. @Test - void testCustomThemeUnderUnmappedLookAndFeelKnownBug() throws Exception { + void testCustomThemeUnderUnmappedLookAndFeel() throws Exception { LookAndFeel original = UIManager.getLookAndFeel(); - UIManager.setLookAndFeel(new NimbusLookAndFeel()); + // The anonymous subclass has a class name that no mapping knows + UIManager.setLookAndFeel(new MetalLookAndFeel() { }); try { - assertThrows(NullPointerException.class, - () -> PlafManager.addCustomTheme(THEME_NAME, new Properties())); + assertNotNull(PlafManager.addCustomTheme(THEME_NAME, new Properties())); } finally { UIManager.setLookAndFeel(original); PlafManager.removeCustomTheme(THEME_NAME); diff --git a/release-notes.txt b/release-notes.txt index 037597a5..fbed0b2a 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -19,6 +19,7 @@ Fixes: * DockingSplitPane: track the divider percentage from the first drag * DockingSplitPane: apply the percentage consistently in setDividerLocation() * DockingSplitPane: keep the percentage set before the size is known +* UIFactory: create a custom theme under a look and feel without a theme mapping == flexdock 1.3 RELEASE NOTES ==