oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.36k stars 1.63k forks source link

Unable to use AWT for 2D drawing #6918

Closed wssy001 closed 6 months ago

wssy001 commented 1 year ago

Describe the issue

When I use GraalVM 22.3.1, I can use AWT for 2D drawing, but after I upgrade to GraalVM 23.0.01, I can't do it

Steps to reproduce the issue Please include both build steps as well as run steps

the test project is here

GraalVM version: GraalVM CE 20.0.1+9.1 (build 20.0.1+9-jvmci-23.0-b12) JDK major version: 20 OS: Ubuntu 20.04 Architecture: arm64

log:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.1)

2023-07-02T14:36:27.512+08:00  INFO 39483 --- [           main] com.example.awttest.AwtTestApplication   : Starting AOT-processed AwtTestApplication using Java 20.0.1 with PID 39483 (/root/awt-test/target/awt-test started by root in /root/awt-test)
2023-07-02T14:36:27.513+08:00  INFO 39483 --- [           main] com.example.awttest.AwtTestApplication   : No active profile set, falling back to 1 default profile: "default"
2023-07-02T14:36:27.522+08:00  INFO 39483 --- [           main] com.example.awttest.AwtTestApplication   : Started AwtTestApplication in 0.143 seconds (process running for 0.183)
Exception in thread "main" java.lang.Error: java.home property not set
        at java.desktop@20.0.1/sun.awt.FontConfiguration.findFontConfigFile(FontConfiguration.java:180)
        at java.desktop@20.0.1/sun.awt.FontConfiguration.<init>(FontConfiguration.java:97)
        at java.desktop@20.0.1/sun.font.MFontConfiguration.<init>(MFontConfiguration.java:48)
        at java.desktop@20.0.1/sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:688)
        at java.desktop@20.0.1/sun.font.SunFontManager$2.run(SunFontManager.java:352)
        at java.desktop@20.0.1/sun.font.SunFontManager$2.run(SunFontManager.java:309)
        at java.base@20.0.1/java.security.AccessController.executePrivileged(AccessController.java:171)
        at java.base@20.0.1/java.security.AccessController.doPrivileged(AccessController.java:319)
        at java.desktop@20.0.1/sun.font.SunFontManager.<init>(SunFontManager.java:309)
        at java.desktop@20.0.1/sun.awt.FcFontManager.<init>(FcFontManager.java:35)
        at java.desktop@20.0.1/sun.awt.X11FontManager.<init>(X11FontManager.java:55)
        at java.desktop@20.0.1/sun.font.PlatformFontInfo.createFontManager(PlatformFontInfo.java:37)
        at java.desktop@20.0.1/sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:51)
        at java.desktop@20.0.1/java.awt.Font.getFont2D(Font.java:526)
        at java.desktop@20.0.1/java.awt.Font.defaultLineMetrics(Font.java:2394)
        at java.desktop@20.0.1/java.awt.Font.getLineMetrics(Font.java:2501)
        at java.desktop@20.0.1/java.awt.font.TextLayout.fastInit(TextLayout.java:597)
        at java.desktop@20.0.1/java.awt.font.TextLayout.<init>(TextLayout.java:392)
        at java.desktop@20.0.1/sun.java2d.SunGraphics2D.drawString(SunGraphics2D.java:2926)
        at com.example.awttest.AwtTestApplication.main(AwtTestApplication.java:47)
fniephaus commented 1 year ago

22.3.1 did not support JDK 20, and AWT internals might have changed from JDK 17/19 to JDK 20. Have you tried regenerating reachability metadata using the tracing agent?

wssy001 commented 1 year ago

22.3.1 did not support JDK 20, and AWT internals might have changed from JDK 17/19 to JDK 20. Have you tried regenerating reachability metadata using the tracing agent?

@fniephaus 1: I know 22.3.1 not support JDK 20. What I want to say is that the same Java code can run in GraalVM version 22.3.1 well 2: I do use the tracing agent and collect a file named jni-config.json. that`s why I can use AWT for 2D drawing in old GraalVM version

chirontt commented 11 months ago

Not sure what is the status of this fairly old issue, but I can reproduce this issue on my Ubuntu 22.04 x64 box, using the latest community versions of GraalVM for JDK 17 & GraalVM for JDK 21, with the java.lang.Error: java.home property not set message output. I use the awt-test project provided by the OP, but with some simplification to remove the Spring framework from it, and the issue is clearly reproducible with pure AWT code (without Spring) for both GraalVM versions. If needed, I can upload my simplified project to GitHub for perusal.

An interesting solution is that if I use the Liberica Native Image Kit to compile the native image of my project, then the resultant executable will work properly, for both JDK 17 & JDK 21 versions of the NIKs. I'm not sure what the differences are in the NIK as compared to the stock GraalVM CE version.

wssy001 commented 6 months ago

finally, I give up. Guys you would rather use javacvthan use AWT