8227441: Enhance logging when reading the fontconfig info file
authorclanger
Tue, 09 Jul 2019 15:58:22 +0200
changeset 58592 fd7e7bb190aa
parent 58328 fe46ee1d42ee
child 58593 da02c2254989
8227441: Enhance logging when reading the fontconfig info file Reviewed-by: prr, mbaesken Contributed-by: matthias.baesken@sap.com, christoph.langer@sap.com
src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java
--- a/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java	Mon Sep 23 17:18:03 2019 +0100
+++ b/src/java.desktop/unix/classes/sun/font/FcFontConfiguration.java	Tue Jul 09 15:58:22 2019 +0200
@@ -25,7 +25,6 @@
 
 package sun.font;
 
-import java.awt.Font;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -45,11 +44,9 @@
 import sun.awt.FontDescriptor;
 import sun.awt.SunToolkit;
 import sun.font.CompositeFontDescriptor;
-import sun.font.FontManager;
 import sun.font.FontConfigManager.FontConfigInfo;
 import sun.font.FontConfigManager.FcCompFont;
 import sun.font.FontConfigManager.FontConfigFont;
-import sun.java2d.SunGraphicsEnvironment;
 import sun.util.logging.PlatformLogger;
 
 public class FcFontConfiguration extends FontConfiguration {
@@ -289,12 +286,10 @@
     /**
      * Gets the OS version string from a Linux release-specific file.
      */
-    private String getVersionString(File f){
-        try {
-            Scanner sc  = new Scanner(f);
+    private String getVersionString(File f) {
+        try (Scanner sc  = new Scanner(f)) {
             return sc.findInLine("(\\d)+((\\.)(\\d)+)*");
-        }
-        catch (Exception e){
+        } catch (Exception e) {
         }
         return null;
     }
@@ -429,23 +424,26 @@
     private void readFcInfo() {
         File fcFile = getFcInfoFile();
         if (!fcFile.exists()) {
+            if (FontUtilities.debugFonts()) {
+                warning("fontconfig info file " + fcFile.toString() + " does not exist");
+            }
             return;
         }
         Properties props = new Properties();
-        FcFontManager fm = (FcFontManager) fontManager;
-        FontConfigManager fcm = fm.getFontConfigManager();
-        try {
-            FileInputStream fis = new FileInputStream(fcFile);
+        try (FileInputStream fis = new FileInputStream(fcFile)) {
             props.load(fis);
-            fis.close();
         } catch (IOException e) {
             if (FontUtilities.debugFonts()) {
-                warning("IOException reading from "+fcFile.toString());
+                warning("IOException (" + e.getCause() + ") reading from " + fcFile.toString());
             }
             return;
         }
         String version = (String)props.get("version");
         if (version == null || !version.equals(fileVersion)) {
+            if (FontUtilities.debugFonts()) {
+                warning("fontconfig info file version mismatch (found: " + version +
+                    ", expected: " + fileVersion + ")");
+            }
             return;
         }
 
@@ -458,6 +456,9 @@
                 fcVersion = Integer.parseInt(fcVersionStr);
                 if (fcVersion != 0 &&
                     fcVersion != FontConfigManager.getFontConfigVersion()) {
+                    if (FontUtilities.debugFonts()) {
+                        warning("new, different fontconfig detected");
+                    }
                     return;
                 }
             } catch (Exception e) {
@@ -480,6 +481,9 @@
             }
             File dirFile = new File(dir);
             if (dirFile.exists() && dirFile.lastModified() > lastModified) {
+                if (FontUtilities.debugFonts()) {
+                    warning("out of date cache directories detected");
+                }
                 return;
             }
             cacheDirIndex++;
@@ -503,6 +507,9 @@
                     String lenStr = (String)props.get(key+".length");
                     int nfonts = Integer.parseInt(lenStr);
                     if (nfonts <= 0) {
+                        if (FontUtilities.debugFonts()) {
+                            warning("bad non-positive .length entry in fontconfig file " + fcFile.toString());
+                        }
                         return; // bad file
                     }
                     fci[index].allFonts = new FontConfigFont[nfonts];
@@ -514,6 +521,9 @@
                         fkey = key+"."+f+".file";
                         String file = (String)props.get(fkey);
                         if (file == null) {
+                            if (FontUtilities.debugFonts()) {
+                                warning("missing file value for key " + fkey + " in fontconfig file " + fcFile.toString());
+                            }
                             return; // bad file
                         }
                         fci[index].allFonts[f].fontFile = file;
@@ -528,6 +538,11 @@
                 warning(t.toString());
             }
         }
+
+        if (FontUtilities.debugFonts()) {
+            PlatformLogger logger = FontUtilities.getLogger();
+            logger.info("successfully parsed the fontconfig file at " + fcFile.toString());
+        }
     }
 
     private static void warning(String msg) {