diff --git a/core/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java b/core/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java index 57c1fb0c..50a3dbe1 100644 --- a/core/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java +++ b/core/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java @@ -27,13 +27,16 @@ import javax.swing.*; import javax.swing.border.Border; import java.awt.*; import java.lang.ref.WeakReference; +import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; public final class DarkBorders { - public static Map> lineBorderMap = new WeakHashMap<>(); - private static Map> lineWidgetBorderMap = new WeakHashMap<>(); + private static Map> lineBorderMap = + Collections.synchronizedMap(new WeakHashMap<>()); + private static Map> lineWidgetBorderMap = + Collections.synchronizedMap(new WeakHashMap<>()); public static Border createLineBorder(final int top, final int left, final int bottom, final int right) { @@ -45,15 +48,17 @@ public final class DarkBorders { final Map> map, final String key) { WeakLineBorder border = new WeakLineBorder(top, left, bottom, right); if (map.containsKey(border)) { - return map.get(border).get(); - } else { - border.setColor(UIManager.getColor(key)); - map.put(border, new WeakReference<>(border)); - return border; + WeakReference ref = map.get(border); + if (ref != null) { + WeakLineBorder b = ref.get(); + if (b != null) return b; + } } + border.setColor(UIManager.getColor(key)); + map.put(border, new WeakReference<>(border)); + return border; } - public static Border createWidgetLineBorder(final int top, final int left, final int bottom, final int right) { return createBorder(top, left, bottom, right, lineWidgetBorderMap, "borderSecondary"); }