all java version: Using AWT in non-headless JRE yields NPE in internal class
Installing the non-headless version of a JRE should include everything needed to run applications in non-headless modes. This mainly affects drawing / printing applications using jfreechart
or batik
.
This is not the case with current java packages in alpine, but also affects other vendors like AdoptOpenJDK (https://github.com/AdoptOpenJDK/openjdk-docker/issues/75).
The stacktrace differes between Java-Version, but looks like this:
Caused by: 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)
and
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)
The error can be reproduced with the following class:
import java.awt.image.BufferedImage;
public class Test {
public static void main(String[] args) {
BufferedImage image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
System.out.println(image.getGraphics());
}
}
The issue can be fixed quite easily by installing a font. But as this error is not intuitive we should install some font by default wehn installing the JRE.
-
openjdk7 -
openjdk8 (!13758 (closed)) -
openjdk9 -
openjdk10 -
openjdk11 -
openjdk12 -
openjdk13 -
openjdk14 -
openjdk15 -
openjdk16