corretto / corretto-docker

Dockerfiles for Amazon Corretto Official images.
https://hub.docker.com/_/amazoncorretto
MIT No Attribution
152 stars 63 forks source link

corretto/java:8 missing libfreetype.so.6 #108

Closed Rachit-10 closed 2 years ago

Rachit-10 commented 2 years ago

Describe the bug

The docker image corretto:8-alpine-jdk is being used to build a Maven Application and during the build process I am encountering an error that libfreetype.so.6 is missing. This library is being called by the Apache POI.

To Reproduce

Environment: Alpine / Java 8 / Spring boot 2.1.x Jib a spring boot 2.1.x app that uses the autoSizeColumn feature of apache-poi and attempt to run the container on your local docker.

OR

Run the following Java Code Snippet:

public class TestApachePOI {
    public static void main(String[] args) {

        XSSFWorkbook xssFWorkbook = new XSSFWorkbook();
        Workbook workBook = new SXSSFWorkbook(xssFWorkbook);
        System.out.println("workBook" + workBook.toString());
    }
}

Following dependencies would be required too:

org.apache.poi:poi-ooxml-schemas:jar:4.1.2:compile
org.apache.poi:poi:jar:5.2.2:compile
org.apache.commons:commons-collections4:jar:4.4:compile
org.apache.commons:commons-math3:jar:3.6.1:compile
com.zaxxer:SparseBitSet:jar:1.2:compile
org.apache.poi:poi-ooxml:jar:5.2.2:compile
org.apache.poi:poi-ooxml-lite:jar:5.2.2:compile
org.apache.commons:commons-compress:jar:1.21:compile
com.github.virtuald:curvesapi:jar:1.07:compile

Screenshots

Error Message image

Lib Directory image

Platform information

Repository: dockerhub
Image tag: 8-alpine-jdk

Additional context

Log output

Caused by: java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-8-amazon-corretto/lib/amd64/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
        at java.lang.Runtime.loadLibrary0(Runtime.java:871)
        at java.lang.System.loadLibrary(System.java:1124)
        at sun.font.FontManagerNativeLibrary$1.run(FontManagerNativeLibrary.java:59)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.FontManagerNativeLibrary.<clinit>(FontManagerNativeLibrary.java:32)
        at sun.font.SunFontManager$1.run(SunFontManager.java:346)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.SunFontManager.<clinit>(SunFontManager.java:342)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82)
        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.canDisplayUpTo(Font.java:2064)
        at java.awt.font.TextLayout.singleFont(TextLayout.java:470)
        at java.awt.font.TextLayout.<init>(TextLayout.java:531)
        at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)
        at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117)
        at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:82)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:684)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:247)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:211)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:186)
        at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:161)
lutkerd commented 2 years ago

Hello, Can you install the Alpine Freetype package with apk add freetype and see if that works for you?

Rachit-10 commented 2 years ago

Hi,

Yes I have tried doing that and in that case I am getting java.lang.NullPointerException.

lutkerd commented 2 years ago

Can you share the full NPE when freetype is installed?

lutkerd commented 2 years ago

I created a simple reproducer without the external dependencies and I had to run apk add freetype fontconfig ttf-dejavu to get it working. Without fontconfig and the ttf-devavu fonts I would get an NPE.

import java.awt.Font;
import java.awt.GraphicsEnvironment;

public class FontTest {
    public static void main(String[] args) {
        Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();

        for (int i = 0; i < fonts.length; i++) {
          System.out.println(fonts[i]);
        }
    }
}

Exception without Fontconfig and ttf-dejavu:

Exception in thread "main" 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:441)
    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 sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:190)
    at sun.java2d.SunGraphicsEnvironment.getAllFonts(SunGraphicsEnvironment.java:209)
    at sun.java2d.HeadlessGraphicsEnvironment.getAllFonts(HeadlessGraphicsEnvironment.java:91)
    at FontTest.main(FontTest.java:7)
Rachit-10 commented 2 years ago

Yes this patch is working for me now.

Although, I would like to have this library packaged in the standard image provided by the corretto. This is because let's say if I upgrade the image version in the future, i would have to manually make these patches through the Dockerfile. Also I have a software which I provide to customers and they would also have to do these patches in case of any upgrade. So I would like to have these libraries be a part of the standard image provided by the corretto itself.

earthling-amzn commented 2 years ago

Closing this in lieu of feature request: https://github.com/corretto/corretto-docker/issues/112