From 87e64ef94292e18105a4bd364f75e7db9b0e9fc5 Mon Sep 17 00:00:00 2001 From: Evgeny Pasynkov Date: Wed, 11 Jul 2012 16:00:17 +0200 Subject: [PATCH] fix incorrect access to dictionary --- .../editor/colors/TextAttributesKeyDefaults.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/editor/colors/TextAttributesKeyDefaults.java b/platform/platform-api/src/com/intellij/openapi/editor/colors/TextAttributesKeyDefaults.java index 5e42329c35ea..b1135b2fa949 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/colors/TextAttributesKeyDefaults.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/colors/TextAttributesKeyDefaults.java @@ -23,7 +23,7 @@ import org.jetbrains.annotations.NotNull; /** * Store default TextAttributes by key */ -public class TextAttributesKeyDefaults { +public abstract class TextAttributesKeyDefaults { private static final TextAttributes NULL_ATTRIBUTES = new TextAttributes(); private static final ConcurrentHashMap ourMap = new ConcurrentHashMap(); @@ -37,7 +37,7 @@ public class TextAttributesKeyDefaults { public static TextAttributes getDefaultAttributes(TextAttributesKey key) { if (!ourMap.containsKey(key)) { // E.g. if one text key reuse default attributes of some other predefined key - ourMap.put(key, null); + ourMap.put(key, NULL_ATTRIBUTES); EditorColorsManager manager = EditorColorsManager.getInstance(); if (manager != null) { // Can be null in test mode @@ -46,12 +46,12 @@ public class TextAttributesKeyDefaults { // try switch from custom colors scheme (e.g. with dark background) to default one. Editor will show // incorrect highlighting with "traces" of color scheme which was active during IDE startup. final EditorColorsScheme defaultColorScheme = manager.getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME); - ourMap.put(key, defaultColorScheme.getAttributes(key)); + final TextAttributes textAttributes = defaultColorScheme.getAttributes(key); + if (textAttributes != null) + ourMap.put(key, textAttributes); } } - if (!ourMap.containsKey(key)) - return NULL_ATTRIBUTES; return ourMap.get(key); } @@ -66,8 +66,8 @@ public class TextAttributesKeyDefaults { @NotNull public static TextAttributesKey createTextAttributesKey(@NonNls @NotNull String externalName, TextAttributes defaultAttributes) { TextAttributesKey key = TextAttributesKey.find(externalName); - if (!ourMap.containsKey(key) || ourMap.get(key) == null) { - ourMap.put(key, defaultAttributes); + if (!ourMap.containsKey(key) || ourMap.get(key) == NULL_ATTRIBUTES) { + ourMap.put(key, defaultAttributes == null ? NULL_ATTRIBUTES : defaultAttributes); } return key; }