-
Bug
-
Resolution: Fixed
-
P3
-
openjdk8u322
-
OS: Linux
OpenJDK 8u built from sources: https://github.com/openjdk/jdk8u-dev/
-
b04
-
generic
-
linux
The issues is reproduced only with OpenJDK. Oracle 1.8.0_351 does not throw the NPE.
OpenJDK 8u built from sources with custom fontconfig.properties file throws NPE:
`
at sun.awt.FcFontManager.getDefaultPlatformFont(FcFontManager.java:76)` on Linux where fontconfig is not installed.
Steps to reproduce:
- Build jdk8u from sources: https://github.com/openjdk/jdk8u-dev/
- Copy attached custom fontconfig.properties file to build/linux-x86_64-normal-server-release/images/j2sdk-image/jre/lib directory
- Run docker with ubuntu 20.04, install dejavu fonts, and freetype (do not install fontconfig)
```
docker run -it ubuntu:20.04 bash
apt update
apt install -y fonts-dejavu
apt install -y libfreetype6
```
- Run HelloImage java sample in the docker with the build jdk
```
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class HelloImage {
public static void main(String[] args) throws Exception {
BufferedImage buff = new BufferedImage(300, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g = buff.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, buff.getWidth(), buff.getHeight());
g.setColor(Color.BLUE);
g.setFont(g.getFont().deriveFont(32f));
g.drawString("Hello, Image!", 50, 50);
g.dispose();
File file = new File("hello-image.png");
ImageIO.write(buff, "png", file);
}
}
```
```
build/linux-x86_64-normal-server-release/images/j2sdk-image/bin/javac HelloImage.java
build/linux-x86_64-normal-server-release/images/j2sdk-image/bin/java HelloImage
Exception in thread "main" java.lang.NullPointerException
at sun.awt.FcFontManager.getDefaultPlatformFont(FcFontManager.java:76)
at sun.font.SunFontManager$2.run(SunFontManager.java:443)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<init>(SunFontManager.java:386)
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 java.awt.Font.getFont2D(Font.java:491)
at java.awt.Font.access$000(Font.java:224)
at java.awt.Font$FontAccessImpl.getFont2D(Font.java:228)
at sun.font.FontUtilities.getFont2D(FontUtilities.java:200)
at sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:669)
at sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D.java:835)
at sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:50)
at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2933)
at HelloImage.main(HelloImage.java:17)
```
OpenJDK 8u built from sources with custom fontconfig.properties file throws NPE:
`
at sun.awt.FcFontManager.getDefaultPlatformFont(FcFontManager.java:76)` on Linux where fontconfig is not installed.
Steps to reproduce:
- Build jdk8u from sources: https://github.com/openjdk/jdk8u-dev/
- Copy attached custom fontconfig.properties file to build/linux-x86_64-normal-server-release/images/j2sdk-image/jre/lib directory
- Run docker with ubuntu 20.04, install dejavu fonts, and freetype (do not install fontconfig)
```
docker run -it ubuntu:20.04 bash
apt update
apt install -y fonts-dejavu
apt install -y libfreetype6
```
- Run HelloImage java sample in the docker with the build jdk
```
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class HelloImage {
public static void main(String[] args) throws Exception {
BufferedImage buff = new BufferedImage(300, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g = buff.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, buff.getWidth(), buff.getHeight());
g.setColor(Color.BLUE);
g.setFont(g.getFont().deriveFont(32f));
g.drawString("Hello, Image!", 50, 50);
g.dispose();
File file = new File("hello-image.png");
ImageIO.write(buff, "png", file);
}
}
```
```
build/linux-x86_64-normal-server-release/images/j2sdk-image/bin/javac HelloImage.java
build/linux-x86_64-normal-server-release/images/j2sdk-image/bin/java HelloImage
Exception in thread "main" java.lang.NullPointerException
at sun.awt.FcFontManager.getDefaultPlatformFont(FcFontManager.java:76)
at sun.font.SunFontManager$2.run(SunFontManager.java:443)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<init>(SunFontManager.java:386)
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 java.awt.Font.getFont2D(Font.java:491)
at java.awt.Font.access$000(Font.java:224)
at java.awt.Font$FontAccessImpl.getFont2D(Font.java:228)
at sun.font.FontUtilities.getFont2D(FontUtilities.java:200)
at sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:669)
at sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D.java:835)
at sun.java2d.pipe.GlyphListPipe.drawString(GlyphListPipe.java:50)
at sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2933)
at HelloImage.main(HelloImage.java:17)
```