JDK-8188030 : AWT java apps fail to start when some minimal fonts are present
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7,8,9,10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-09-27
  • Updated: 2020-02-03
  • Resolved: 2017-10-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 7 JDK 8
10 b31Fixed 7u271Fixed 8u192Fixed
Related Reports
Duplicate :  
Relates :  
During initialisation of the fonts, there is a fixed number of fonts to retrieve that depends on the names defined in FontConfigManager.fontConfigNames.

The native code asks fontconfig the best match for those fonts, but in certain cases, namely when only CFF fonts are installed fontconfig (even in addition to the minimum mandatory Type 1 ones), fontconfig returns the CFF as "best match".

This happens, for example, when requesting a font of type "sans:regular:roman". CFF are valid fonts for fontconfig (and are effectively Type 1 OpenType fonts) so the match is registered, but then the actual set returned by fontconfig contains only CFF fonts that are then discarded, thus causing an array of 0 size for "sans:regular:roman", that later on causes an ArrayIndexOutOfBound when this array is accessed in java code:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
	at sun.font.CompositeStrike.getStrikeForSlot(CompositeStrike.java:75)
	at sun.font.CompositeStrike.getFontMetrics(CompositeStrike.java:93)
	at sun.font.FontDesignMetrics.initMatrixAndMetrics(FontDesignMetrics.java:359)
	at sun.font.FontDesignMetrics.<init>(FontDesignMetrics.java:350)
	at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:302)
	at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1113)
	at javax.swing.JComponent.getFontMetrics(JComponent.java:1626)
	at ...

On RHEL 7.4 for example, with STIX fonts and the following fonts:


you can see what  fc-match -f "sans:regular:roman" -sv returns, which is similar to what the code in the JDK does (output edited):

Pattern has 34 elts (size 48)
	family: "STIX"(s)
	fontformat: "CFF"(w)
	postscriptname: "STIX-Regular"(w)

Pattern has 34 elts (size 48)
	family: "Cantarell"(s)
	fontformat: "CFF"(w)
	postscriptname: "Cantarell-Regular"(w)

Pattern has 34 elts (size 48)
	family: "STIX"(s)
	fontformat: "CFF"(w)
	postscriptname: "STIX-Bold"(w)

Pattern has 34 elts (size 48)
	family: "STIX"(s)
	fontformat: "CFF"(w)
	postscriptname: "STIX-Italic"(w)

Pattern has 34 elts (size 48)
	family: "STIX"(s)
	fontformat: "CFF"(w)
	postscriptname: "STIX-BoldItalic"(w)

Review: http://mail.openjdk.java.net/pipermail/2d-dev/2017-September/008573.html http://mail.openjdk.java.net/pipermail/2d-dev/2017-September/008576.html

I'm not sure how to attach a file in Jira, anyway, here is a simple reproducer: // see: https://stackoverflow.com/questions/45569367/upgrade-rhel-from-7-3-to-7-4-arrayindexoutofboundsexception-in-sun-font-composi import java.awt.*; import java.awt.font.*; public class TestJava { public static void main(String[] args) { String []fontFamilies = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); for (String font : fontFamilies) { System.err.println(font); } Font font = new Font("SansSerif", Font.PLAIN, 12); //Font font = new Font("STIX", Font.PLAIN, 12); FontRenderContext frc = new FontRenderContext(null, false, false); TextLayout layout = new TextLayout("\ude00", font, frc); layout.getCaretShapes(0); System.out.println(layout); } }

Proposed fix: http://cr.openjdk.java.net/~neugens/8188030/webrev.01/

You can reference the following bug report on Red Hat bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1484079