Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) when using install4j caused by font config missing #693

Closed
xinyi9 opened this issue Oct 29, 2018 · 22 comments · Fixed by itzg/docker-bungeecord#35
Labels
bug Issues that are problems in the code as reported by the community x-linux Issues that affect or relate to the x64/x32 LINUX OS
Milestone

Comments

@xinyi9
Copy link

xinyi9 commented Oct 29, 2018

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

@xinyi9 xinyi9 changed the title NPE when using install4j caused by font config missing NPE at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) when using install4j caused by font config missing Oct 29, 2018
@ChristianCiach
Copy link

See also AdoptOpenJDK/openjdk-docker#75

@karianna karianna added this to TODO in temurin-build via automation Oct 29, 2018
@karianna karianna added the bug Issues that are problems in the code as reported by the community label Oct 29, 2018
@karianna
Copy link
Contributor

karianna commented Oct 29, 2018

Thinking out loud - this looks like an issue where we'd need to get upstream to backport this support from Java 11 or someone to add a patch to the 8u project.

Might be an installer issue as well, let's see.

@minhtran83
Copy link

@karianna The installer bootstraps the JEditorPane.setText() and that goes through this code path

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 

That happens because the font directory that Adopt OpenJDK should provide does not exist

It is great if we can backport that from Java 11 to 8u project.

@xinyi9
Copy link
Author

xinyi9 commented Nov 11, 2018

Thinking out loud - this looks like an issue where we'd need to get upstream to backport this support from Java 11 or someone to add a patch to the 8u project.

Might be an installer issue as well, let's see.

Hey @karianna thanks for the comments.

Would there be an estimated timeline that this issue will be addressed, say in short-term(weeks), or longer term(months)?
This information will be helpful for us to plan support for our customer and reduce negative impact.

@karianna
Copy link
Contributor

Probably longer term at this stage.

@jarnbjo
Copy link

jarnbjo commented Nov 19, 2018

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:

version=1
sequence.allfonts=default

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.

@cristatus
Copy link

Same problem with fontconfig 2:2.13.1 (on arch linux). I tried loading fontconfig library manually and I saw following error:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: /usr/lib/libfontconfig.so.1.12.0: /usr/lib/libfontconfig.so.1.12.0: undefined symbol: FT_Done_MM_Var
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	...

It means the included jre/lib/amd64/libfreetype.so.6 is not compatible with system fontconfig. I removed jre/lib/amd64/libfreetype.so.6 and problem solved.

@keertz04
Copy link

keertz04 commented Jan 24, 2019

@jarnbjo Thanks for your solution. I was able to mitigate the problem with the NullPointerException in FontConfiguration.java:1264 on alphine Linux

Currently facing

Caused by: java.lang.NullPointerException: null
hub_1           | 	at sun.awt.FcFontManager.getDefaultPlatformFont(FcFontManager.java:76)
hub_1           | 	at sun.font.SunFontManager$2.run(SunFontManager.java:433)
hub_1           | 	at java.security.AccessController.doPrivileged(Native Method)
hub_1           | 	at sun.font.SunFontManager.<init>(SunFontManager.java:376)
hub_1           | 	at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
hub_1           | 	at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
hub_1           | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
hub_1           | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
hub_1           | 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
hub_1           | 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
hub_1           | 	at java.lang.Class.newInstance(Class.java:442)
hub_1           | 	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
hub_1           | 	at java.security.AccessController.doPrivileged(Native Method)
hub_1           | 	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
hub_1           | 	at sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:190)
hub_1           | 	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:224)
hub_1           | 	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:252)
hub_1           | 	at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:94)
hub_1           | 	at net.sf.jasperreports.engine.util.JRGraphEnvInitializer.initializeGraphEnv(JRGraphEnvInitializer.java:57)

Any help is appreciated!!
Distribution : jdk8u202-b08 Linux x64

@karianna karianna added this to the January 2019 milestone Jan 24, 2019
@jgkirschbaum
Copy link

Installing packages fontconfig and urw-fonts on CentOS 6 & 7 fixed the issue.

@karianna karianna modified the milestones: January 2019, February 2019 Feb 3, 2019
@xinyi9
Copy link
Author

xinyi9 commented Feb 6, 2019

Hi @keertz04 I experienced the same thing when debugging into the source code. By supplying fontconfig.properties it is able to get rid of the NPE at FontConfiguration, but it uncovered another NPE as you showed because system fonts are still not available, and it will throws exceptions when it tries to get default platform font.
Currently, We still use the workaround to install fontconfig

@xinyi9
Copy link
Author

xinyi9 commented Feb 6, 2019

Just fyi for folks who use install4j, the latest release 7.0.9 has included the changes
Added a workaround for an InternalError when a bundled JRE could not find fonts on Linux
https://www.ej-technologies.com/download/install4j/changelog.html

Our team has not upgraded to this version, think might be worth a heads-up here though.

@tbuckel
Copy link

tbuckel commented Feb 7, 2019

+1 for the fontconfig workaround, and didn't need to use fontconfig.properties. (jdk8u202-b08)

@JarrettSpiker
Copy link

JarrettSpiker commented Feb 14, 2019

@xinyi9 good catch with the install4j release note. Unfortunately, I just tried to build an installer using install4j 7.0.9 and still see the issue:
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 com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:85) at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:62)

This is on x86_64 Clearlinux 4.14.21-380.lts, using jdk8u192-b12

@regentov
Copy link

Currently facing

Caused by: java.lang.NullPointerException: null
hub_1           | 	at sun.awt.FcFontManager.getDefaultPlatformFont(FcFontManager.java:76)
hub_1           | 	at sun.font.SunFontManager$2.run(SunFontManager.java:433)

@keertz04 the same for me, after installing fontconfig and adding fontconfig.properties.
So not fixed, on alpine.

@blop
Copy link

blop commented May 21, 2020

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

@mkurz
Copy link

mkurz commented May 27, 2020

Installing fontconfig on Ubuntu 16.04 server fixed the problem for me. No need to add fontconfig.properties fortunately (makes OpenJDK upgrades easier):

$ sudo apt-get install fontconfig
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  fontconfig-config fonts-dejavu-core libfontconfig1
The following NEW packages will be installed:
  fontconfig fontconfig-config fonts-dejavu-core libfontconfig1
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/1398 kB of archives.
After this operation, 4490 kB of additional disk space will be used.

Looks like fonts-dejavu-core is important as well. Without it another exception occurs.

Using JRE 11 (yes, the JRE download, not JDK):

$ java -version
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)

@VsterLong
Copy link

replace image with java:8, perfect!

@johngh
Copy link

johngh commented Jun 25, 2020

On Red Hat 7.7, we first tried the creating fontconfig.properties with no joy.
We had fontconfig installed, but not urw-fonts.
Installing the superseding package urw-base35-fonts resolved the issue.

@karianna karianna added this to To do in Top Priorities via automation Jun 25, 2020
@jirkafm
Copy link

jirkafm commented Aug 4, 2020

On Red Hat 7.7, we first tried the creating fontconfig.properties with no joy.
We had fontconfig installed, but not urw-fonts.
Installing the superseding package urw-base35-fonts resolved the issue.

Hi,

for me it was enough to install missing fontconfig and introduce fontconfig.properties mentioned earlier in $JAVA_HOME/lib.

My env:
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7)
fontconfig-2.13.0-4.3.el7.x86_64

@robinson-calderon
Copy link

@jarnbjo Thanks for your solution. I was able to mitigate the problem with the NullPointerException in FontConfiguration.java:1264 on alphine Linux

Currently facing

Caused by: java.lang.NullPointerException: null
hub_1           | 	at sun.awt.FcFontManager.getDefaultPlatformFont(FcFontManager.java:76)
hub_1           | 	at sun.font.SunFontManager$2.run(SunFontManager.java:433)
hub_1           | 	at java.security.AccessController.doPrivileged(Native Method)
hub_1           | 	at sun.font.SunFontManager.<init>(SunFontManager.java:376)
hub_1           | 	at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
hub_1           | 	at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
hub_1           | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
hub_1           | 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
hub_1           | 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
hub_1           | 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
hub_1           | 	at java.lang.Class.newInstance(Class.java:442)
hub_1           | 	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
hub_1           | 	at java.security.AccessController.doPrivileged(Native Method)
hub_1           | 	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
hub_1           | 	at sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:190)
hub_1           | 	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:224)
hub_1           | 	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:252)
hub_1           | 	at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:94)
hub_1           | 	at net.sf.jasperreports.engine.util.JRGraphEnvInitializer.initializeGraphEnv(JRGraphEnvInitializer.java:57)

Any help is appreciated!!
Distribution : jdk8u202-b08 Linux x64

hi, I spent days suffering with it until I saw this github thread and made the night happy

corretto/corretto-11#124 (comment)

CDFN pushed a commit to CDFN/docker-bungeecord that referenced this issue Aug 25, 2020
This change fixes adoptium/temurin-build#693 bug, which caused NPE when interacting with fonts.
itzg pushed a commit to itzg/docker-bungeecord that referenced this issue Aug 25, 2020
This change fixes adoptium/temurin-build#693 bug, which caused NPE when interacting with fonts.
@karianna
Copy link
Contributor

See there were no fonts in the Linux version adoptium/adoptium-support#70

temurin-build automation moved this from TODO to Done Oct 19, 2020
Top Priorities automation moved this from To do to Done Oct 19, 2020
@karianna karianna added this to the October 2020 milestone Oct 19, 2020
@karianna karianna removed the Marlin Marlin Rendering issues (jdk8) label Oct 19, 2020
@dbaylerg
Copy link

dbaylerg commented Feb 19, 2021

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

This also fixes the issue if your Docker container is build on top of openjdk:8-jre-alpine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that are problems in the code as reported by the community x-linux Issues that affect or relate to the x64/x32 LINUX OS
Projects
No open projects
temurin-build
  
Done
Development

Successfully merging a pull request may close this issue.