Skip to content

Commit

Permalink
8263138: Initialization of sun.font.SunFontManager.platformFontMap is…
Browse files Browse the repository at this point in the history
… not thread safe

Reviewed-by: aivanov, kizune, serb
  • Loading branch information
turbanoff authored and mrserb committed Mar 20, 2021
1 parent 5b8233b commit ab66d69
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/java.desktop/share/classes/sun/font/SunFontManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1433,9 +1433,10 @@ public static class FamilyDescription {
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.
Expand All @@ -1445,8 +1446,10 @@ public HashMap<String, FamilyDescription> populateHardcodedFileNameMap() {
}

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) {
Expand All @@ -1460,7 +1463,7 @@ Font2D findFontFromPlatformMap(String lcName, int style) {
}

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,
Expand Down Expand Up @@ -1527,7 +1530,7 @@ Font2D findFontFromPlatformMap(String lcName, int style) {
if (FontUtilities.isLogging()) {
FontUtilities.logInfo("Hardcoded file missing looking for " + lcName);
}
platformFontMap.remove(firstWord);
fd.failed = true;
return null;
}

Expand All @@ -1554,7 +1557,7 @@ public Boolean run() {
if (FontUtilities.isLogging()) {
FontUtilities.logInfo("Hardcoded file missing looking for " + lcName);
}
platformFontMap.remove(firstWord);
fd.failed = true;
return null;
}

Expand Down

1 comment on commit ab66d69

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.