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 in sun.awt.FontConfiguration.getVersion(...) #326

Open
mattpsvreis opened this issue May 25, 2023 · 5 comments
Open

NPE in sun.awt.FontConfiguration.getVersion(...) #326

mattpsvreis opened this issue May 25, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@mattpsvreis
Copy link

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:

#AdoptOpenJDK/openjdk-docker#75

@mattpsvreis mattpsvreis added the bug Something isn't working label May 25, 2023
@lutkerd
Copy link
Contributor

lutkerd commented May 25, 2023

Can try apk add fontconfig ttf-dejavu and let me know if that works for you?

@mattpsvreis
Copy link
Author

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!

@benty-amzn
Copy link
Contributor

The output from -Dsun.java2d.debugfonts=warning mentioned in the other issue would be helpful here as well if you can provide it

@lutkerd
Copy link
Contributor

lutkerd commented May 26, 2023

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.

@jcarroyo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants