NPE from sun.awt.FontConfiguration.getVersion using Apache FOP JDK 11 on Linux system
Asked Answered
R

1

9

I am using Apache FOP (v 2.3 and with testing v 2.5). I have recently upgraded from Oracle JDK 8 to Oracle JDK 11. I am using JBoss EAP 7.2 on Oracle Linux (which is RedHat derivative). Everything works fine when using JDK 8, but just the upgrade to JDK 11 has caused my FOP XSLTs for XML -> PDF and XML - > PNG to create the below stacktrace (the FOP version did not matter as produced the same error).

Caused by: java.lang.NullPointerException
        at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1262)
        at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:225)
        at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:107)
        at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:719)

My font is Google/RedHat's LiberationSans and I have put them on the file system and configured in a file called LiberationSans.xconf. I have made sure the files are global read accessible (775) and are owned by the user that is running the JBoss instance.

<?xml version="1.0"?>
<!-- LiberationSans -->
<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <fonts>
        <font embed-url="/apps/fonts/LiberationSans-Regular.ttf" embedding-mode="subset">
          <font-triplet name="LiberationSans" style="normal" weight="normal"/>
        </font>
        <font embed-url="/apps/fonts/LiberationSans-Bold.ttf" embedding-mode="subset">
          <font-triplet name="LiberationSans" style="normal" weight="bold"/>
        </font>
      </fonts>
    </renderer>
    <renderer mime="image/png">
      <fonts>
       <font embed-url="/apps/fonts/LiberationSans-Regular.ttf" embedding-mode="subset">
          <font-triplet name="LiberationSans" style="normal" weight="normal"/>
        </font>
        <font embed-url="/apps/fonts/LiberationSans-Bold.ttf" kerning="yes" embedding-mode="subset">
          <font-triplet name="LiberationSans" style="normal" weight="bold"/>
        </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

Everything works fine on my local windows machine but my deployments are via Eclipse/JBoss plugins so there might be something with that. The deployments on the Linux server is via jboss-cli.

Please let me know if there is anything else I can provide that might help. If we have to migrate away from FOP, I would like that to be a last resort.

Ruin answered 30/12, 2020 at 15:39 Comment(0)
R
20

Turns out the issue was not that I didn't have access to the fonts, the Linux OS required me to install fontconfig via yum.

yum install fontconfig

I am not sure why Oracle JDK 11 plus the missing Linux utility was the issue since this works now in my production environment with Oracle JDK 1.8 and without fontconfig being installed.

Ruin answered 31/12, 2020 at 19:13 Comment(2)
Some minimalistic distros (i.e. Alpine) may also need some font package, for example ttf-dejavu.Coterie
@Coterie how to install ttf-dejavu?Undertenant

© 2022 - 2024 — McMap. All rights reserved.