Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8188030

AWT java apps fail to start when some minimal fonts are present

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 7, 8, 9, 10
    • Fix Version/s: 10
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b31

      Description

      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:

      xorg-x11-fonts-Type1-7.5-9.el7.noarch
      stix-fonts-1.1.0-5.el7.noarch

      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)

        Activity

        neugens Mario Torre created issue -
        neugens Mario Torre made changes -
        Field Original Value New Value
        Assignee Mario Torre [ neugens ]
        neugens Mario Torre made changes -
        Description 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 ...

        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:

        xorg-x11-fonts-Type1-7.5-9.el7.noarch
        stix-fonts-1.1.0-5.el7.noarch

        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)
        Hide
        neugens Mario Torre added a comment -
        You can reference the following bug report on Red Hat bugzilla:

        https://bugzilla.redhat.com/show_bug.cgi?id=1484079
        Show
        neugens Mario Torre added a comment - You can reference the following bug report on Red Hat bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1484079
        Show
        neugens Mario Torre added a comment - Proposed fix: http://cr.openjdk.java.net/~neugens/8188030/webrev.01/
        Hide
        neugens Mario Torre added a comment -
        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);
          }
        }

        Show
        neugens Mario Torre added a comment - 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);   } }
        neugens Mario Torre made changes -
        Affects Version/s 8 [ 11815 ]
        Affects Version/s 7 [ 11810 ]
        Affects Version/s 9 [ 14949 ]
        Affects Version/s 10 [ 16302 ]
        vdyakov Victor Dyakov made changes -
        Fix Version/s 10 [ 16302 ]
        andrew Andrew Hughes made changes -
        Status New [ 10000 ] Open [ 1 ]
        bvaidya Balchandra Vaidya made changes -
        Subcomponent java.awt [ 196 ]
        bvaidya Balchandra Vaidya made changes -
        Labels bugdb_26767156
        Show
        vdyakov Victor Dyakov added a comment - 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
        vdyakov Victor Dyakov made changes -
        Link This issue relates to JDK-8187811 [ JDK-8187811 ]
        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk10/client/rev/d5a1cde89944
        User: neugens
        Date: 2017-10-30 12:19:08 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk10/client/rev/d5a1cde89944 User: neugens Date: 2017-10-30 12:19:08 +0000
        hgupdate HG Updates made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolved In Build team [ 17324 ]
        Resolution Fixed [ 1 ]
        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk10/master/rev/d5a1cde89944
        User: prr
        Date: 2017-11-03 17:49:11 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk10/master/rev/d5a1cde89944 User: prr Date: 2017-11-03 17:49:11 +0000
        hgupdate HG Updates made changes -
        Resolved In Build team [ 17324 ] master [ 18256 ]
        hgupdate HG Updates made changes -
        Resolved In Build master [ 18256 ] b31 [ 17504 ]
        prr Philip Race made changes -
        Link This issue duplicates JDK-8187811 [ JDK-8187811 ]

          People

          • Assignee:
            neugens Mario Torre
            Reporter:
            neugens Mario Torre
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: