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

Phil Race philip.race at oracle.com
Tue Jun 4 22:29:31 UTC 2013


Why didn't it return any fonts ? Is this because the libfontconfig 
library isn't installed ?

We've been runtime loading that lib but these days could potentially
switch to linking against it at compile time, in which case you won't
even get this far. So in other words this could be a system config issue.
The most common thing I've seen is that 64 bit Linux doesn't have
all the libs to run a 32 bit JRE. You probably found and fixed all of those
because it was Unsatisfiedlinkerror or similar but the runtime linking
is disguising that its really the same problem.

If you really don't have any fonts installed, then that's also
a missing package and we perhaps should have a better diagnostic,
but there isn't really any point in continuing anyway without any fonts.
Even headless applications may require fonts.


On 6/4/2013 2:50 PM, Jeremy Manson wrote:
> Hi folks,
> I encountered a NullPointerException in the above method, when 
> fontconfig doesn't return any fonts:
> http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/7eae7c89dab4/src/solaris/classes/sun/awt/X11FontManager.java
> Line 779.  The issue is that FontConfigManager sets fontConfigFonts to 
> null when Fontconfig doesn't return any fonts:
> http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/7eae7c89dab4/src/solaris/classes/sun/font/FontConfigManager.java
> 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 
> b/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 <http://logger.info>("Fontconfig returned no fonts at all.");
>              }
>              fontConfigFailed = true;
> +            fontConfigFonts = new FcCompFont[0];
>              return;
>          } else if (fontConfigFailed) {
>              for (int i = 0; i< fontArr.length; i++) {
> Thanks for your attention!
> Jeremy

More information about the 2d-dev mailing list