Skip to content

Using Java AWT Fonts gives unsatisfiedlinkerror while running native image #2729

@Mahaswami

Description

@Mahaswami

Describe the issue

Trying to get AWT fonts working in native mode. Below is the code. It uses java.awt and simply prints the available font family names.

public class MainClass {
    public static void main(String[] args) {
        String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
         for ( int i = 0; i < fonts.length; i++ ) {
             System.out.println(fonts[i]);
         }
    }
}

Running the native image gives the following error.

Exception in thread "main" java.lang.InternalError: java.lang.reflect.InvocationTargetException
	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:86)
	at java.security.AccessController.doPrivileged(AccessController.java:83)
	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
	at sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:189)
	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:223)
	at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:251)
	at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:75)
	at com.mahaswami.nativeimage.MainClass.main(MainClass.java:8)
Caused by: java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:84)
	... 7 more
Caused by: java.lang.UnsatisfiedLinkError: sun.font.FontConfigManager.getFontConfigVersion()I [symbol: Java_sun_font_FontConfigManager_getFontConfigVersion or Java_sun_font_FontConfigManager_getFontConfigVersion__]
	at com.oracle.svm.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:145)
	at com.oracle.svm.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:57)
	at sun.font.FontConfigManager.getFontConfigVersion(FontConfigManager.java)
	at sun.font.FcFontConfiguration.readFcInfo(FcFontConfiguration.java:455)
	at sun.font.FcFontConfiguration.init(FcFontConfiguration.java:94)
	at sun.font.FcFontConfiguration.<init>(FcFontConfiguration.java:76)
	at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:713)
	at sun.font.SunFontManager$2.run(SunFontManager.java:367)
	at java.security.AccessController.doPrivileged(AccessController.java:83)
	at sun.font.SunFontManager.<init>(SunFontManager.java:312)
	at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
	at sun.awt.X11FontManager.<init>(X11FontManager.java:56)
	... 9 more

Since FontConfigManager.getFontConfigVersion() uses libfontconfig, tried to load the libfontconfig.so at runtime but it did not help.

Steps to reproduce the issue

The reproducer project is available at
https://github.com/MahaswamiSoftware/awtfont-native-image

Describe GraalVM and your environment:

  • GraalVM version : [CE 20.1.0]
  • JDK major version: [11]
  • OS: [linux mint]
  • Architecture: [AMD64]

More details
Contents of jni config file

[
{
  "name":"java.lang.ClassLoader",
  "methods":[
    {"name":"getPlatformClassLoader","parameterTypes":[] }, 
    {"name":"loadClass","parameterTypes":["java.lang.String"] }
  ]
},
{
  "name":"java.lang.ClassNotFoundException"
},
{
  "name":"java.lang.NoSuchMethodError"
},
  {
    "name": "sun.font.FontConfigManager",
    "methods": [
      {"name": "getFontConfigVersion","parameterTypes":[]}
    ]
  }
]

Contents of reflection config file

[
  {
    "name": "sun.awt.X11FontManager",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredFields" : true,
    "allPublicFields" : true
  },
  {
    "name": "sun.font.FontConfigManager",
    "methods": [
      {"name": "getFontConfigVersion","parameterTypes":[]}
    ]
  }
]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions