From 89b9ed52134b78d18bffe8a165b392a35ef5cd54 Mon Sep 17 00:00:00 2001 From: weisj Date: Sun, 21 Jun 2020 21:56:54 +0200 Subject: [PATCH] Ensure uri is loaded when calling #getName. --- .../github/weisj/darklaf/icons/DarkSVGIcon.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java index 85407027..139bbecb 100644 --- a/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java +++ b/property-loader/src/main/java/com/github/weisj/darklaf/icons/DarkSVGIcon.java @@ -129,10 +129,7 @@ public class DarkSVGIcon implements DerivableIcon, RotateIcon, Seri private boolean ensureSVGLoaded() { if (!loaded.get()) { - if (uri == null && uriSupplier != null) { - uri = uriSupplier.get(); - uriSupplier = null; - } + ensureURILoaded(); LOGGER.fine(() -> "Loading icon '" + uri.toASCIIString() + "'."); icon.setSvgURI(uri); loaded.set(true); @@ -141,6 +138,16 @@ public class DarkSVGIcon implements DerivableIcon, RotateIcon, Seri return false; } + private void ensureURILoaded() { + if (uri == null && uriSupplier != null) { + uri = uriSupplier.get(); + uriSupplier = null; + } + if (uri == null) { + throw new IllegalStateException("Uri is null."); + } + } + protected void updateCache(final boolean update, final Component c) { GraphicsConfiguration gc = c != null ? c.getGraphicsConfiguration() : null; double sx = Scale.getScaleX(gc); @@ -175,6 +182,7 @@ public class DarkSVGIcon implements DerivableIcon, RotateIcon, Seri } protected String getName() { + ensureURILoaded(); String name = uri.toASCIIString(); name = name.substring(Math.min(name.length() - 1, name.lastIndexOf('/') + 1)); return name;