quarkus: AWT extension fails native build because "Classes that should be initialized at run time got initialized during image building"

Describe the bug

I wrote a program that creates Thumbnails for images. It uses the Thumbnailator library. For native execution, Quarkus needs the AWT extension - it through a Add AWT Quarkus extension to enable Java2D/ImageIO without it. But building a native image with the AWT extension fails.

Expected behavior

./mvnw clean install -Dnative in my project completes.

Actual behavior

./mvnw clean install -Dnative in my project completes fails:

[2/7] Performing analysis...  [*]                                                                        (9.4s @ 2.01GB)
   6,107 (81.40%) of  7,502 classes reachable
   9,736 (62.35%) of 15,614 fields reachable
  25,346 (45.04%) of 56,274 methods reachable
     223 classes,     1 fields, and 1,371 methods registered for reflection
       1 native library: -framework CoreServices

Error: Classes that should be initialized at run time got initialized during image building:
 sun.awt.SunHints the class was requested to be initialized at run time (from feature io.quarkus.awt.runtime.graal.AwtFeature.afterRegistration with 'sun.awt'). To see why sun.awt.SunHints got initialized use --trace-class-initialization=sun.awt.SunHints
java.awt.RenderingHints the class was requested to be initialized at run time (from feature io.quarkus.awt.runtime.graal.AwtFeature.afterRegistration with 'java.awt'). To see why java.awt.RenderingHints got initialized use --trace-class-initialization=java.awt.RenderingHints
To see how the classes got initialized, use --trace-class-initialization=sun.awt.SunHints,java.awt.RenderingHints
com.oracle.svm.core.util.UserError$UserException: Classes that should be initialized at run time got initialized during image building:
 sun.awt.SunHints the class was requested to be initialized at run time (from feature io.quarkus.awt.runtime.graal.AwtFeature.afterRegistration with 'sun.awt'). To see why sun.awt.SunHints got initialized use --trace-class-initialization=sun.awt.SunHints
java.awt.RenderingHints the class was requested to be initialized at run time (from feature io.quarkus.awt.runtime.graal.AwtFeature.afterRegistration with 'java.awt'). To see why java.awt.RenderingHints got initialized use --trace-class-initialization=java.awt.RenderingHints
To see how the classes got initialized, use --trace-class-initialization=sun.awt.SunHints,java.awt.RenderingHints
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:73)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ProvenSafeClassInitializationSupport.checkDelayedInitialization(ProvenSafeClassInitializationSupport.java:273)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.duringAnalysis(ClassInitializationFeature.java:164)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$10(NativeImageGenerator.java:748)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:85)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:748)
	at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.AbstractAnalysisEngine.runAnalysis(AbstractAnalysisEngine.java:162)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:745)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:578)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:535)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:580)
	at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
------------------------------------------------------------------------------------------------------------------------
                        0.4s (2.7% of total time) in 16 GCs | Peak RSS: 2.40GB | CPU load: 4.09
========================================================================================================================
Failed generating 'bug-quarkus-awt-extension-1.0-runner' after 15.5s.
Error: Image build request failed with exit status 1

How to Reproduce?

  1. Clone my repo.
  2. Run ./mvnw clean install -Dnative.

Output of uname -a or ver

Darwin m1x-773.local 22.3.0 Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version “17.0.5” 2022-10-18 OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08) OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.16.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /Users/karsten/.m2/wrapper/dists/apache-maven-3.8.6-bin/67568434/apache-maven-3.8.6 Java version: 17.0.5, vendor: GraalVM Community, runtime: /Users/karsten/.sdkman/candidates/java/22.3.r17-grl Default locale: en_US, platform encoding: UTF-8 OS name: “mac os x”, version: “13.2”, arch: “aarch64”, family: “mac”

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

@geoand @Karm I finally created a repo that demonstrates this bug. I updated the description accordingly. The application works from the IDE and when running as an uber JAR but fails the native build.

The error doesn’t show with light use of the AWT extension - say, instantiating an Image. For me, it only shows when using the Thumbnailator library.

@Karm Thank you! You answered all my questions.