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

libfreetype.dylib is incorrectly packaged #6

Closed
bturner opened this issue Nov 14, 2018 · 9 comments
Closed

libfreetype.dylib is incorrectly packaged #6

bturner opened this issue Nov 14, 2018 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@bturner
Copy link

bturner commented Nov 14, 2018

Describe the bug

When using AWT fonts, initializing sun.font.CFontManager fails with the following error:

/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib: dlopen(/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib, 1): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
  Referenced from: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib
  Reason: image not found
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1122)
	at sun.font.FontManagerNativeLibrary$1.run(FontManagerNativeLibrary.java:61)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.FontManagerNativeLibrary.<clinit>(FontManagerNativeLibrary.java:32)
	at sun.font.SunFontManager$1.run(SunFontManager.java:339)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.SunFontManager.<clinit>(SunFontManager.java:335)
	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.canDisplay(Font.java:1980)

Looking in /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib shows there's a misnamed libfreetype.dylib.6 (should be libfreetype.6.dylib), but even fixing that name doesn't allow AWT to initialize successfully because it's explicitly looking in /opt/X11/lib.

This appears to be quite similar to adoptium/temurin-build#202, but not quite the same. With AdoptOpenJDK, the issue can be fixed simply by renaming libfreetype.dylib.6 to libfreetype.6.dylib while leaving the library in jre/lib.

To Reproduce

import java.awt.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class FontBug {

    private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";

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

        List<Font> usableFonts = Arrays.stream(fonts)
                // Calling Font.canDisplay here will fail                
                .filter(font -> ALPHABET.chars().allMatch(font::canDisplay))
                .collect(Collectors.toList());
        System.out.println("Usable fonts: " + usableFonts.size());
    }
}

Expected behavior

CFontManager initializes successfully and AWT fonts work.

Platform information

OS: macOS 10.14.1 (Mojave)
Version: build 1.8.0_192-amazon-corretto-preview-b12

Additional context

I got this failure from the (defunct, but still generally functional) JCaptcha library, but it's not unique to JCaptcha (as shown by my simple reproduction, which uses nothing but standard Java).

@ziyiluo ziyiluo added the bug Something isn't working label Nov 14, 2018
@jguo11
Copy link
Contributor

jguo11 commented Nov 15, 2018

Thank you for reporting this issue to us. The Corretto engineering team is looking at it and we will post updates here.

@jasonmcintosh
Copy link

Clean install on OS X, trying to run jmeter trigger this which I think is the same issue:

An error occurred: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib: dlopen(/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib, 1): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
  Referenced from: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib
  Reason: image not found

@ziyiluo
Copy link
Contributor

ziyiluo commented Nov 15, 2018

The libfontmanager in Corretto is linked to the libfreetype in X11 and breaks when X11 is not installed. The libfreetype is actually bundled with Corretto so relinking libfontmanager to the bundled libfreetype will fix this issue. We plan to address this in the next release. Until then, here’s a simple workaround on your own mac:

# Assume you installed Corretto thru the installer
export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home

sudo install_name_tool -id @rpath/libfreetype.dylib.6 $JAVA_HOME/jre/lib/libfreetype.dylib.6
sudo install_name_tool -change /opt/X11/lib/libfreetype.6.dylib @rpath/libfreetype.dylib.6 $JAVA_HOME/jre/lib/libfontmanager.dylib

@ziyiluo ziyiluo self-assigned this Nov 15, 2018
@li-a
Copy link

li-a commented Nov 16, 2018

FWIW, I hit this from Swing code --

java.lang.UnsatisfiedLinkError: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib: dlopen(/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib, 1): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
  Referenced from: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib
  Reason: image not found
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at sun.lwawt.macosx.LWCToolkit$1.run(LWCToolkit.java:93)
    at sun.lwawt.macosx.LWCToolkit$1.run(LWCToolkit.java:80)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.lwawt.macosx.LWCToolkit.<clinit>(LWCToolkit.java:79)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at java.awt.Toolkit$2.run(Toolkit.java:860)
    at java.awt.Toolkit$2.run(Toolkit.java:855)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
    at javax.swing.RepaintManager.<clinit>(RepaintManager.java:238)
    at javax.swing.JComponent.repaint(JComponent.java:4792)
    at java.awt.Component.repaint(Component.java:3311)
    at javax.swing.AbstractButton.setModel(AbstractButton.java:1784)
    at javax.swing.JButton.<init>(JButton.java:134)
    at javax.swing.JButton.<init>(JButton.java:110)

... and @ziyiluo's workaround worked.

@krishnamanchikalapudi
Copy link

Any update on below error...

java -version

openjdk version "1.8.0_192" OpenJDK Runtime Environment (build 1.8.0_192-amazon-corretto-preview-b12) OpenJDK 64-Bit Server VM (build 25.192-b12, mixed mode)

ERROR

AWT is not properly configured on this server. Perhaps you need to run your container with "-Djava.awt.headless=true"? See also: https://jenkins.io/redirect/troubleshooting/java.awt.headless

java.lang.UnsatisfiedLinkError: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib: dlopen(/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib, 1): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
  Referenced from: /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/jre/lib/libfontmanager.dylib
  Reason: image not found
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1122)
	at sun.font.FontManagerNativeLibrary$1.run(FontManagerNativeLibrary.java:61)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.FontManagerNativeLibrary.<clinit>(FontManagerNativeLibrary.java:32)
	at sun.font.SunFontManager$1.run(SunFontManager.java:339)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.font.SunFontManager.<clinit>(SunFontManager.java:335)
	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.getFamily(Font.java:1220)
	at java.awt.Font.getFamily_NoClientCode(Font.java:1194)
	at java.awt.Font.getFamily(Font.java:1186)
	at java.awt.Font.toString(Font.java:1683)
	at hudson.util.ChartUtil.<clinit>(ChartUtil.java:260)
	at hudson.WebAppMain.contextInitialized(WebAppMain.java:192)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4643)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5109)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:986)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1858)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
	at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:772)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:426)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1585)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:308)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
	at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424)
	at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:367)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:972)
	at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1432)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1422)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
	at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:944)
	at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:261)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:801)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:695)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

@ziyiluo
Copy link
Contributor

ziyiluo commented Dec 12, 2018

Hi @krishnamanchikalapudi , have you tried the workaround in my previous comment?

@ziyiluo ziyiluo added this to the Preview Bug Fixes milestone Dec 15, 2018
@krishnamanchikalapudi
Copy link

@ziyiluo thank you!... Solution worked for MAC 10.14.3

@ziyiluo
Copy link
Contributor

ziyiluo commented Dec 18, 2018

This issue is fixed in the new Corretto preview release (1.8.0_192-amazon-corretto-preview2-b12). Change log of this release is now available. You can find the builds in the Corretto download page. Please let us know if you have any further questions. We appreciate your report!

@barracuda156
Copy link

@ziyiluo You saved my day :)

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

7 participants