flow: Missing native-image hints for PWA icon

Description of the bug

Running a Vaadin 24.3.7 application with @PWA and a custom icon (located at src/main/resources/META-INF/resources/icons/icon.png), compiled into a native image using GraalVM 21 results in the following errors. Interestingly, the Tracing Agent did not provide the anticipated hints during initial testing.

java.lang.NoClassDefFoundError: Could not initialize class java.awt.GraphicsEnvironment$LocalGE
        at java.desktop@21.0.2/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:106) ~[addons-demos-24-native.exe:na]
        at java.desktop@21.0.2/java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1182) ~[addons-demos-24-native.exe:na]
        at com.vaadin.flow.server.PwaIcon.drawIconImage(PwaIcon.java:268) ~[na:na]
java.lang.NoSuchMethodError: sun.awt.windows.WToolkit.windowsSettingChange()V
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1341) ~[na:na]
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1326) ~[na:na]
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetMethodID(JNIFunctions.java:431) ~[na:na]
        at java.desktop@21.0.2/sun.awt.windows.WToolkit.initIDs(Native Method) ~[na:na]
        at java.desktop@21.0.2/sun.awt.windows.WToolkit.<clinit>(WToolkit.java:190) ~[na:na]
        at java.desktop@21.0.2/sun.awt.Win32GraphicsEnvironment.<clinit>(Win32GraphicsEnvironment.java:60) ~[na:na]
        at java.desktop@21.0.2/sun.awt.PlatformGraphicsInfo.createGE(PlatformGraphicsInfo.java:34) ~[na:na]
        at java.desktop@21.0.2/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:93) ~[na:na]
        at java.desktop@21.0.2/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:84) ~[na:na]
        at java.desktop@21.0.2/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:106) ~[addons-demos-24-native.exe:na]
        at java.desktop@21.0.2/java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1182) ~[addons-demos-24-native.exe:na]
        at com.vaadin.flow.server.PwaIcon.drawIconImage(PwaIcon.java:268) ~[na:na]

#16307 also mentions the following hint, which in my case was produced by the Tracing Agent:

{
  "name":"sun.java2d.Disposer",
  "methods":[{"name":"addRecord","parameterTypes":["java.lang.Object","long","long"] }]
}

Expected behavior

In 2022 @mstahv said that “Vaadin don’t yet come with these hints”, but now there is VaadinHintsRegistrar and the documentation does not mention a word about hints, so I’m inclined to think that I could expect it to work.

Icon generation in native apps seems to be a known issue, though https://github.com/vaadin/flow/issues/16307#issuecomment-1602241827.

Minimal reproducible example

A Vaadin 24.3.7 application with @PWA and a custom icon.

Versions

  • Vaadin / Flow version: 24.3.7
  • Java version: GraalVM version 21.0.2+13.1
  • OS version: Windows 10.0.19045.4170

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

Could we just try to fix this “properly”? To me the AWT usage at runtime sounds like a design bug we should fix. It makes some raster images scaling? Shouldn’t that be done when doing a production build of the client bundle?

#20516 generates PWA icons at build time

Tested against 24.6-SNAPSHOT and there the exception is not thrown anymore when the images are pregenerated.

I mentioned the Quarkus class only because the hints in Flow were updated based on it