Browse Source

Fixed possible NPE.

pull/127/head
weisj 5 years ago
parent
commit
2cd80fdbcc
  1. 21
      core/src/main/java/com/github/weisj/darklaf/components/border/DarkBorders.java

21
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 javax.swing.border.Border;
import java.awt.*; import java.awt.*;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.WeakHashMap;
public final class DarkBorders { public final class DarkBorders {
public static Map<WeakLineBorder, WeakReference<WeakLineBorder>> lineBorderMap = new WeakHashMap<>(); private static Map<WeakLineBorder, WeakReference<WeakLineBorder>> lineBorderMap =
private static Map<WeakLineBorder, WeakReference<WeakLineBorder>> lineWidgetBorderMap = new WeakHashMap<>(); Collections.synchronizedMap(new WeakHashMap<>());
private static Map<WeakLineBorder, WeakReference<WeakLineBorder>> lineWidgetBorderMap =
Collections.synchronizedMap(new WeakHashMap<>());
public static Border createLineBorder(final int top, final int left, final int bottom, final int right) { 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<WeakLineBorder, WeakReference<WeakLineBorder>> map, final String key) { final Map<WeakLineBorder, WeakReference<WeakLineBorder>> map, final String key) {
WeakLineBorder border = new WeakLineBorder(top, left, bottom, right); WeakLineBorder border = new WeakLineBorder(top, left, bottom, right);
if (map.containsKey(border)) { if (map.containsKey(border)) {
return map.get(border).get(); WeakReference<WeakLineBorder> ref = map.get(border);
} else { if (ref != null) {
border.setColor(UIManager.getColor(key)); WeakLineBorder b = ref.get();
map.put(border, new WeakReference<>(border)); if (b != null) return b;
return border; }
} }
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) { public static Border createWidgetLineBorder(final int top, final int left, final int bottom, final int right) {
return createBorder(top, left, bottom, right, lineWidgetBorderMap, "borderSecondary"); return createBorder(top, left, bottom, right, lineWidgetBorderMap, "borderSecondary");
} }

Loading…
Cancel
Save