temurin-build: NPE at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) when using install4j caused by font config missing
Hi there, Our team hit a NPE problem on install4j on various Linux distributions. (Ubuntu, Centos, Debian etc) JDK version: jdk8u181-b13
When installing our product using installer4j, we got a null pointer exception caused by missing fontconfig, stack trace as follows:
java.lang.NullPointerException at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219) at sun.awt.FontConfiguration.init(FontConfiguration.java:107) at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774) at sun.font.SunFontManager$2.run(SunFontManager.java:431) at java.security.AccessController.doPrivileged(Native Method) at sun.font.SunFontManager.<init>(SunFontManager.java:376) at sun.awt.FcFontManager.<init>(FcFontManager.java:35) at sun.awt.X11FontManager.<init>(X11FontManager.java:57) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83) at java.security.AccessController.doPrivileged(Native Method) at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) at sun.font.SunFontManager.getInstance(SunFontManager.java:250) at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264) at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1113) at javax.swing.JComponent.getFontMetrics(JComponent.java:1626) at javax.swing.text.WrappedPlainView.updateMetrics(WrappedPlainView.java:318) at javax.swing.text.WrappedPlainView.updateChildren(WrappedPlainView.java:297) at javax.swing.text.WrappedPlainView.insertUpdate(WrappedPlainView.java:463) at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1610) at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1869) at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:201) at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:748) at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707) at javax.swing.text.PlainDocument.insertString(PlainDocument.java:130) at javax.swing.text.DefaultEditorKit.read(DefaultEditorKit.java:273) at javax.swing.JEditorPane.setText(JEditorPane.java:1416) at javax.swing.JEditorPane.<init>(JEditorPane.java:290) at com.install4j.runtime.installer.frontend.headless.AbstractHeadlessScreenExecutor.init(AbstractHeadlessScreenExecutor.java:68) at com.install4j.runtime.installer.frontend.headless.ConsoleScreenExecutor.<init>(ConsoleScreenExecutor.java:24) at com.install4j.runtime.installer.frontend.headless.InstallerConsoleScreenExecutor.<init>(InstallerConsoleScreenExecutor.java:6) at com.install4j.runtime.installer.Installer.getScreenExecutor(Installer.java:88) at com.install4j.runtime.installer.Installer.runInProcess(Installer.java:57) at com.install4j.runtime.installer.Installer.main(Installer.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:85) at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:62)
Currently we use a workaround to install font dependency by
apt install fontconfig
However, this workaround will change behaviour when our customer switches from Oracle jdk to AdoptOpenJDK, and remains a compatibility issue for us.
Would the team consider bundle the font config in the JDK and help fix it in further versions?
Cheers,
Distribution : jdk8u181-b13 Linux x64
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 16
- Comments: 22 (3 by maintainers)
Commits related to this issue
- Add fontconfig and ttf-dejavu packages This change fixes https://github.com/AdoptOpenJDK/openjdk-build/issues/693 bug, which caused NPE when interacting with fonts. — committed to CDFN/docker-bungeecord by deleted user 4 years ago
- Add fontconfig and ttf-dejavu packages (#35) This change fixes https://github.com/AdoptOpenJDK/openjdk-build/issues/693 bug, which caused NPE when interacting with fonts. — committed to itzg/docker-bungeecord by deleted user 4 years ago
Installing packages fontconfig and urw-fonts on CentOS 6 & 7 fixed the issue.
The NullPointerException in FontConfiguration.java:1264 is caused by a missing font configuration file, which is not included with the Linux version of AdoptOpenJDK. It is important to notice that the direct cause of the exception is a missing configuration file and not that actual font files are missing.
When the AWT font subsystem is initialized, it will look for a font configuration file in $JAVA_HOME/lib following a naming scheme and priority as described here: https://docs.oracle.com/javase/8/docs/technotes/guides/intl/fontconfig.html
Even if no fonts are provided by the JDK and use of OS provided fonts is not intented or configured, a minimal configuration is required by the AWT font subsystem to initialize without throwing exceptions. Providing a fontconfig.properties file in $JAVA_HOME/lib with the following two lines will at least, to start with, mitigate the problem with the NullPointerException:
Since we are only using fonts bundled with our application, this is a feasible workaround in our situation. It allows the font subsystem to initialize and we can later without issues load our own fonts from the classpath. I am not sure what happens and YMMV if you try to run an application, which relies on the JDK to provide actual fonts, either as bundled with the JDK or as provided by the operating system.
This also fixes the issue if your Docker container is build on top of openjdk:8-jre-alpine
Using
adoptopenjdk/openjdk11-openj9:jdk-11.0.7_10_openj9-0.20.0-alpine-slim
I just had to run :apk add --no-cache fontconfig ttf-dejavu
@jarnbjo Thanks for your solution. I was able to mitigate the problem with the NullPointerException in FontConfiguration.java:1264 on alphine Linux
Currently facing
Any help is appreciated!! Distribution : jdk8u202-b08 Linux x64
+1 for the fontconfig workaround, and didn’t need to use fontconfig.properties. (jdk8u202-b08)
Installing
fontconfig
on Ubuntu 16.04 server fixed the problem for me. No need to addfontconfig.properties
fortunately (makes OpenJDK upgrades easier):Looks like
fonts-dejavu-core
is important as well. Without it another exception occurs.Using JRE 11 (yes, the JRE download, not JDK):
Same problem with fontconfig 2:2.13.1 (on arch linux). I tried loading fontconfig library manually and I saw following error:
It means the included
jre/lib/amd64/libfreetype.so.6
is not compatible with system fontconfig. I removedjre/lib/amd64/libfreetype.so.6
and problem solved.