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

ImageIO requires -H:+ForeignAPISupport to try to lookup fonts #277

Merged
merged 3 commits into from
Aug 19, 2024

Conversation

Karm
Copy link
Owner

@Karm Karm commented Aug 15, 2024

Surpasses #276
Fixes #262

@jerboaa So, this is unrelated to oracle/graal#9300. JDK 24 with Graal master now requires -H:+ForeignAPISupport. I will have to take a look at it in Quarkus too.

Exception in thread "main" java.io.IOException: Problem reading font data.
    at java.desktop@24-internal/java.awt.Font.createFont0(Font.java:1205)
    at java.desktop@24-internal/java.awt.Font.createFont(Font.java:1076)
    at imageio.Main.loadFonts(Main.java:139)
    at imageio.Main.paintRectangles(Main.java:97)
    at imageio.Main.main(Main.java:195)
    at java.base@24-internal/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: Support for the Java Foreign Function and Memory API is not active: enable with -H:+ForeignAPISupport
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:121)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.ForeignDisabledSubstitutions.fail(ForeignDisabledSubstitutions.java:175)
    at java.base@24-internal/jdk.internal.foreign.layout.AbstractLayout.varHandle(AbstractLayout.java:152)
    at java.desktop@24-internal/sun.font.StrikeCache.getVarHandle(StrikeCache.java:134)
    at java.desktop@24-internal/sun.font.StrikeCache.<clinit>(StrikeCache.java:139)
    at java.desktop@24-internal/sun.font.PhysicalStrike.<clinit>(PhysicalStrike.java:41)
    at java.base@24-internal/java.lang.Class.ensureInitialized(DynamicHub.java:655)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.FindClass(JNIFunctions.java:374)
    at java.desktop@24-internal/sun.font.SunFontManager.initIDs(Native Method)
    at java.desktop@24-internal/sun.font.SunFontManager$1.run(SunFontManager.java:273)
    at java.desktop@24-internal/sun.font.SunFontManager$1.run(SunFontManager.java:267)
    at java.base@24-internal/java.security.AccessController.executePrivileged(AccessController.java:132)
    at java.base@24-internal/java.security.AccessController.doPrivileged(AccessController.java:319)
    at java.desktop@24-internal/sun.font.SunFontManager.initStatic(SunFontManager.java:267)
    at java.desktop@24-internal/sun.font.SunFontManager.<clinit>(SunFontManager.java:262)
    at java.base@24-internal/java.lang.Class.ensureInitialized(DynamicHub.java:655)
    at java.base@24-internal/java.lang.Class.ensureInitialized(DynamicHub.java:655)
    at java.desktop@24-internal/sun.font.PlatformFontInfo.createFontManager(PlatformFontInfo.java:37)
    at java.desktop@24-internal/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:51)
    at java.desktop@24-internal/java.awt.Font.createFont0(Font.java:1167)

With vanilla JDK, you don't see this whole stacktrace, you just see unhelpful:

Exception in thread "main" java.io.IOException: Problem reading font data.
    at java.desktop@24-beta/java.awt.Font.createFont0(Font.java:1205)
    at java.desktop@24-beta/java.awt.Font.createFont(Font.java:1076)
    at imageio.Main.loadFonts(Main.java:139)
    at imageio.Main.paintRectangles(Main.java:97)
    at imageio.Main.main(Main.java:195)
    at java.base@24-beta/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

That is because of this in JDK:

--- a/src/java.desktop/share/classes/java/awt/Font.java
+++ b/src/java.desktop/share/classes/java/awt/Font.java
@@ -1202,7 +1202,7 @@ public Void run() {
             if (cause instanceof FontFormatException) {
                 throw (FontFormatException)cause;
             }
-            throw new IOException("Problem reading font data.");
+            throw new IOException("Problem reading font data.", t);
         }
     }
 
~

@Karm Karm requested a review from jerboaa August 15, 2024 22:56
@Karm Karm self-assigned this Aug 15, 2024
@jerboaa
Copy link
Collaborator

jerboaa commented Aug 16, 2024

@Karm #262 fails on JDK 23 based Mandrel (24.1) and JDK 24 based Mandrel (24.2). You are enabling ForeignAPISupport only for 24.2. Have you verified this is not needed for Mandrel 24.1? Thanks!

@Karm
Copy link
Owner Author

Karm commented Aug 17, 2024

@jerboaa This PR passes for me with what we have in our Mandrel 24.1 branch:

 Java version: 23-beta+36-ea, vendor version: Mandrel-24.1.0.0-dev7c3531a005f

minus warning (oracle/graal#9057) , whitelisted....

Copy link
Collaborator

@jerboaa jerboaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me if tests pass with this on 24.2 (JDK 24) and 24.1 (JDK 23). There might be a change in the JDK (JDK 24+) that uses the new foreign API, requiring the change in JDK 24-based Mandrel only.

@Karm
Copy link
Owner Author

Karm commented Aug 19, 2024

@jerboaa O.K., I'll move this forward and revisit as needed.

@Karm Karm merged commit 9f6c895 into master Aug 19, 2024
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[24.1] imageio AWT tests fail with JDK 23 ea
2 participants