[OpenJDK 2D-Dev] NPE in X11FontManager.getDefaultPlatformFont

Jeremy Manson jeremymanson at google.com
Tue Jun 4 21:50:05 UTC 2013

Hi folks,

I encountered a NullPointerException in the above method, when fontconfig
doesn't return any fonts:


Line 779.  The issue is that FontConfigManager sets fontConfigFonts to null
when Fontconfig doesn't return any fonts:


Line 218.

The solution I came up with is to initialize fontConfigFonts with a
zero-element array in this case:

diff --git a/src/solaris/classes/sun/font/FontConfigManager.java
--- a/src/solaris/classes/sun/font/FontConfigManager.java
+++ b/src/solaris/classes/sun/font/FontConfigManager.java
@@ -216,6 +216,7 @@
                 logger.info("Fontconfig returned no fonts at all.");
             fontConfigFailed = true;
+            fontConfigFonts = new FcCompFont[0];
         } else if (fontConfigFailed) {
             for (int i = 0; i< fontArr.length; i++) {

Thanks for your attention!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/2d-dev/attachments/20130604/bb576151/attachment.html>

More information about the 2d-dev mailing list