NPE in sun.awt.FontConfiguration.getVersion(...)
mattpsvreis opened this issue · 5 comments
Describe the bug
Hello.
When using the org.apache.poi.hssf.usermodel.HSSFWorkbook
lib to generate a stylized CSV in a private project the following stack trace error frequently occurs, but only when running in a Linux Environment through a Docker Container that uses an Alpine JDK.
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)
at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:367)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:312)
at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
The stack trace above happens when using the autoSizeColumn()
function from the Sheet
class that was generated by the createSheet()
function from the HSSFWorkbook
class from the package org.apache.poi.hssf.usermodel.HSSFWorkbook
while running in a Docker container that uses amazoncorretto:11-alpine-jdk
as the image for Java, using the Spring Boot Framework.
After digging through many GitHub issues I stumbled upon an AdoptOpenJDK GitHub issue that mentioned this and it had some suggested fixes.
The final definitive workaround suggested there was to add this to the Dockerfile:
RUN apk add --no-cache fontconfig
RUN ln -s /usr/lib/libfontconfig.so.1 /usr/lib/libfontconfig.so && \
ln -s /lib/libuuid.so.1 /usr/lib/libuuid.so.1 && \
ln -s /lib/libc.musl-x86_64.so.1 /usr/lib/libc.musl-x86_64.so.1
ENV LD_LIBRARY_PATH /usr/lib
But it didn't work for amazoncorretto:11-alpine-jdk
. The same stack error trace occurred. So I'm posting this GitHub issue to get further help, or enlighten a bug that might exist.
Here's a reference to the original GitHub issue that provided the suggested above workaround that ended up not working:
Can try apk add fontconfig ttf-dejavu
and let me know if that works for you?
Can try
apk add fontconfig ttf-dejavu
and let me know if that works for you?
That was also one of the suggested methods and didn't turn out any good. Same errors!
The output from -Dsun.java2d.debugfonts=warning
mentioned in the other issue would be helpful here as well if you can provide it
Do you have a simple reproducer for this? In the past it has always worked with fontconfig and ttf-dejavu installed, the reproducers we've used previously are working as expected for me on the current amazoncorretto:11-alpine-jdk images.
Any update on this?
I'm having the same issue when building a Java application with gradle.
My system configuration is:
cat /etc/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.18.2 PRETTY_NAME="Alpine Linux v3.18" HOME_URL="https://alpinelinux.org/" BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
I have added the following dependencies:
RUN apk update \ && apk upgrade \ && apk add curl wget dpkg shadow make zip fontconfig ttf-dejavu chromium e2fsprogs-extra