JDK-7068471 : NPE in sun.font.FontConfigManager.getFontConfigFont() when libfontconfig.so is not installed
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7,8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux_oracle_6.0
  • CPU: generic,x86
  • Submitted: 2011-07-19
  • Updated: 2013-06-26
  • Resolved: 2011-09-16
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 7 JDK 8
7u40Fixed 8 b01Fixed
Related Reports
Duplicate :  
Description
From the 2d-dev mailing list :-
http://mail.openjdk.java.net/pipermail/2d-dev/2011-July/002090.html

Hi all, a problem was discovered on JDK7 when using the Nimbus L&F on a system where libfontconfig.so was not installed (On AIX actually but in theory on any unix system)

Under the covers Nimbus uses the sun.font.FontConfigManager to retrieve fonts. sun.font.FontConfigManager in turn is intended to use (for a unix system) the libfontconfig.so system library if present.

The code is intended to cope with the library being missing but it unfortunately doesn't. A array is referenced without checking if it is null. On systems where the system library is present this array is never null but in this specific case the array is null and the reference fails as follows.

���
Exception in thread "main" java.lang.NullPointerException
at sun.font.FontConfigManager.getFontConfigFont(FontConfigManager.java:352)
at sun.awt.X11FontManager.getFontConfigFUIR(X11FontManager.java:817)
at sun.font.FontUtilities.getFontConfigFUIR(FontUtilities.java:472)
at javax.swing.plaf.nimbus.NimbusDefaults.<init>(NimbusDefaults.java:138)
at javax.swing.plaf.nimbus.NimbusLookAndFeel.<init>(NimbusLookAndFeel.java:100)
at Nimbus.main(Nimbus.java:6)
���

The fix is trivial (see below) and probably just tactical. 

diff --git a/src/solaris/classes/sun/font/FontConfigManager.java b/src/solaris/classes/sun/font/FontConfigManager.java
--- a/src/solaris/classes/sun/font/FontConfigManager.java
+++ b/src/solaris/classes/sun/font/FontConfigManager.java
@@ -348,6 +348,8 @@

         initFontConfigFonts(false);

+    if(fontConfigFonts==null) return null; // init failed
+
         FcCompFont fcInfo = null;
         for (int i=0; i<fontConfigFonts.length; i++) {
             if (name.equals(fontConfigFonts[i].fcFamily) &&

Comments
EVALUATION As per description
19-07-2011