bell-sw / Liberica

Free and 100% open source Progressive Java Runtime for modern Java™ deployments supported by a leading OpenJDK contributor
https://bell-sw.com/pages/libericajdk/
GNU General Public License v2.0
323 stars 28 forks source link

"Fontconfig head is null, check your fonts or fonts configuration" with liberica-openjdk-alpine:17.0.10 #169

Closed rgambelli closed 7 months ago

rgambelli commented 7 months ago

Hi all,

we are converting our microservices application to use liberica-openjdk-alpine:17.0.10 in place of eclipse-temurin:17-jdk-alpine, our dockerfile generally is simple like this:

FROM bellsoft/liberica-openjdk-alpine:17.0.10
RUN apk update && apk add tzdata && apk --no-cache add curl

RUN apk --no-cache add msttcorefonts-installer fontconfig && \
    update-ms-fonts && \
    fc-cache -f

we have just found an issue that we haven't with eclipse-temurin image, it seems a font issue or something related to Graphics2D, here follows the stacktrace:

java.lang.InternalError: java.lang.reflect.InvocationTargetException
    at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:87)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
    at java.desktop/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:75)
    at java.desktop/sun.font.SunFontManager.getInstance(SunFontManager.java:248)
    at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:266)
    at java.desktop/sun.java2d.SunGraphics2D.getFontMetrics(SunGraphics2D.java:863)
    at org.activiti.image.impl.DefaultProcessDiagramCanvas.initialize(DefaultProcessDiagramCanvas.java:218)
    at org.activiti.image.impl.DefaultProcessDiagramCanvas.<init>(DefaultProcessDiagramCanvas.java:174)
    at it.cbt.org.activiti.image.impl.CustomProcessDiagramCanvas.<init>(CustomProcessDiagramCanvas.java:40)
    at it.cbt.org.activiti.image.impl.CustomProcessDiagramGenerator.initProcessDiagramCanvas(CustomProcessDiagramGenerator.java:314)
    at it.cbt.org.activiti.image.impl.CustomProcessDiagramGenerator.generateProcessDiagram(CustomProcessDiagramGenerator.java:326)
    at org.activiti.image.impl.DefaultProcessDiagramGenerator.generateDiagram(DefaultProcessDiagramGenerator.java:403)
    ...
    at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.reflect.InvocationTargetException: null
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at java.desktop/sun.font.FontManagerFactory$1.run(FontManagerFactory.java:85)
    ... 160 common frames omitted
Caused by: java.lang.RuntimeException: Fontconfig head is null, check your fonts or fonts configuration
    at java.desktop/sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1271)
    at java.desktop/sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:224)
    at java.desktop/sun.awt.FontConfiguration.init(FontConfiguration.java:106)
    at java.desktop/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:706)
    at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:358)
    at java.desktop/sun.font.SunFontManager$2.run(SunFontManager.java:315)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
    at java.desktop/sun.font.SunFontManager.<init>(SunFontManager.java:315)
    at java.desktop/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
    at java.desktop/sun.awt.X11FontManager.<init>(X11FontManager.java:56)
    ... 166 common frames omitted

Fontconfig is installed:

/opt/my-container $ apk list --installed
...
fontconfig-2.14.2-r4 x86_64 {fontconfig} (MIT) [installed]
...

Could you help us find a solution? Thanks

voitylov commented 7 months ago

Please check if [1] helps.

I'l like to note that the images you use are Alpine with glibc planted inside it, and Liberica there is a glibc variant. This can cause crashes as pointed out in the issue. Because of that, please consider other images, such as liberica-runtime-container. It's based on Alpaquita Linux, we created this Linux distribution specifically to address this kind of issues, it has two variants: one based on musl and another based on glibc. Hence you can choose one based on you application dependencies.

[1] https://github.com/bell-sw/Liberica/issues/25 [2] https://hub.docker.com/r/bellsoft/liberica-runtime-container

voitylov commented 7 months ago

If this does not help, please provide a log with -Dsun.java2d.debugfonts=true

rgambelli commented 7 months ago

Thanks @voitylov, we have just found that using bellsoft/liberica-openjdk-alpine-musl:17.0.10 resolved our problem, looking carefully what I used before, it was musl too, so for me it's better remain in musl (consider that I don't really know which are the differences between glibc and musl, can you explain in short?)

I would like to point you that at the end of this https://hub.docker.com/r/bellsoft/liberica-openjdk-alpine there is a section talking about Font issues but the hint suggested doesn't work

Thanks

voitylov commented 7 months ago

musl [1] and glibc [2] are two different implementations of the C standard library. Liberica provides binaries for both implementations. From a practical, java developer standpoint what is important is that binary compatibility between the two standard libraries is very limited, rendering it nearly impossible to load an .so compiled for, say, glibc on musl system.

If you were running on musl-based system, you should either use liberica-openjdk-alpine-musl (which has Alpine as the base OS) or liberica-runtime-container with tag musl (which has Alpaquita as the base OS). Both are a good choice.

[1] https://musl.libc.org/ [2] https://www.gnu.org/software/libc/