6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
authorprr
Fri, 14 Aug 2009 14:25:22 -0700
changeset 3931 81071c37cc91
parent 3930 738bc2599ca8
child 3932 c9cd7ff79037
6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08 Reviewed-by: igor, jgodinez
jdk/src/solaris/classes/sun/font/FontConfigManager.java
jdk/src/solaris/native/sun/awt/fontpath.c
--- a/jdk/src/solaris/classes/sun/font/FontConfigManager.java	Wed Aug 12 17:21:08 2009 +0200
+++ b/jdk/src/solaris/classes/sun/font/FontConfigManager.java	Fri Aug 14 14:25:22 2009 -0700
@@ -194,18 +194,36 @@
             fontArr[i].style = i % 4; // depends on array order.
         }
         getFontConfig(getFCLocaleStr(), fcInfo, fontArr, includeFallbacks);
+        FontConfigFont anyFont = null;
         /* If don't find anything (eg no libfontconfig), then just return */
         for (int i = 0; i< fontArr.length; i++) {
             FcCompFont fci = fontArr[i];
             if (fci.firstFont == null) {
                 if (FontUtilities.isLogging()) {
                     Logger logger = FontUtilities.getLogger();
-                    logger.info("Fontconfig returned no fonts.");
+                    logger.info("Fontconfig returned no font for " +
+                                fontArr[i].fcName);
                 }
                 fontConfigFailed = true;
+            } else if (anyFont == null) {
+                anyFont = fci.firstFont;
+            }
+        }
+
+        if (anyFont == null) {
+            if (FontUtilities.isLogging()) {
+                Logger logger = FontUtilities.getLogger();
+                logger.info("Fontconfig returned no fonts at all.");
                 return;
             }
+        } else if (fontConfigFailed) {
+            for (int i = 0; i< fontArr.length; i++) {
+                if (fontArr[i].firstFont == null) {
+                    fontArr[i].firstFont = anyFont;
+                }
+            }
         }
+
         fontConfigFonts = fontArr;
 
         if (FontUtilities.isLogging()) {
--- a/jdk/src/solaris/native/sun/awt/fontpath.c	Wed Aug 12 17:21:08 2009 +0200
+++ b/jdk/src/solaris/native/sun/awt/fontpath.c	Fri Aug 14 14:25:22 2009 -0700
@@ -1203,11 +1203,7 @@
          * Inspect the returned fonts and the ones we like (adds enough glyphs)
          * are added to the arrays and we increment 'fontCount'.
          */
-        if (includeFallbacks) {
-            nfonts = fontset->nfont;
-        } else {
-            nfonts = 1;
-        }
+        nfonts = fontset->nfont;
         family   = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
         styleStr = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
         fullname = (FcChar8**)calloc(nfonts, sizeof(FcChar8*));
@@ -1249,7 +1245,7 @@
              * adversely affects load time for minimal value-add.
              * This is still likely far more than we've had in the past.
              */
-            if (nfonts==10) {
+            if (j==10) {
                 minGlyphs = 50;
             }
             if (unionCharset == NULL) {
@@ -1268,6 +1264,9 @@
             (*FcPatternGetString)(fontPattern, FC_FAMILY, 0, &family[j]);
             (*FcPatternGetString)(fontPattern, FC_STYLE, 0, &styleStr[j]);
             (*FcPatternGetString)(fontPattern, FC_FULLNAME, 0, &fullname[j]);
+            if (!includeFallbacks) {
+                break;
+            }
         }
 
         /* Once we get here 'fontCount' is the number of returned fonts
@@ -1309,6 +1308,8 @@
                 }
                 if (includeFallbacks) {
                     (*env)->SetObjectArrayElement(env, fcFontArr, fn++,fcFont);
+                } else {
+                    break;
                 }
             }
         }