diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java index ec360f9dcca..baf1e92f66d 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java @@ -196,7 +196,7 @@ void addAllocatedFontsToStale(Font defaultFont) { * (key type: String, * value type: org.eclipse.swt.graphics.FontData[]). */ - private final Map stringToFontData = new HashMap<>(7); + private final Map stringToFontData = new ConcurrentHashMap<>(7); /** * Collection of Fonts that are now stale to be disposed @@ -816,14 +816,15 @@ private void put(String symbolicName, FontData[] fontData, boolean update) { Assert.isNotNull(symbolicName); Assert.isNotNull(fontData); - FontData[] existing = stringToFontData.get(symbolicName); + // single atomic read-modify-write; replacing an equal mapping with the + // given, content-equal one is a no-op for every reader + FontData[] existing = stringToFontData.put(symbolicName, fontData); if (Arrays.equals(existing, fontData)) { return; } FontRecord oldFont = stringToFontRecord .remove(symbolicName); - stringToFontData.put(symbolicName, fontData); if (update) { fireMappingChanged(symbolicName, existing, fontData); }