8263138: Initialization of sun.font.SunFontManager.platformFontMap is not thread safe

Reviewed-by: aivanov, kizune, serb
This commit is contained in:
Andrey Turbanov 2021-03-20 07:45:02 +00:00 committed by Sergey Bylokhov
parent 5b8233ba0a
commit ab66d6991d

@ -1433,9 +1433,10 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
public String boldFileName;
public String italicFileName;
public String boldItalicFileName;
boolean failed;
}
static HashMap<String, FamilyDescription> platformFontMap;
static volatile HashMap<String, FamilyDescription> platformFontMap;
/**
* default implementation does nothing.
@ -1445,8 +1446,10 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
}
Font2D findFontFromPlatformMap(String lcName, int style) {
HashMap<String, FamilyDescription> platformFontMap = SunFontManager.platformFontMap;
if (platformFontMap == null) {
platformFontMap = populateHardcodedFileNameMap();
SunFontManager.platformFontMap = platformFontMap;
}
if (platformFontMap == null || platformFontMap.size() == 0) {
@ -1460,7 +1463,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
}
FamilyDescription fd = platformFontMap.get(firstWord);
if (fd == null) {
if (fd == null || fd.failed) {
return null;
}
/* Once we've established that its at least the first word,
@ -1527,7 +1530,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
if (FontUtilities.isLogging()) {
FontUtilities.logInfo("Hardcoded file missing looking for " + lcName);
}
platformFontMap.remove(firstWord);
fd.failed = true;
return null;
}
@ -1554,7 +1557,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
if (FontUtilities.isLogging()) {
FontUtilities.logInfo("Hardcoded file missing looking for " + lcName);
}
platformFontMap.remove(firstWord);
fd.failed = true;
return null;
}