-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Describe the issue
While working on quarkusio/quarkus#36378 I came across the following issue.
When using -H:ThrowMissingRegistrationErrors= -H:MissingRegistrationReportingMode=Exit at build time the resulting native image throws an exception if it tries to access a resource that is not available but was registered.
The native image should not throw a missing registration error in that case, as the resource is actually registered (in resource-config.json) despite not existing.
cc @vjovanov
Steps to reproduce the issue
cd /tmp
git clone --branch 2024-06-04-missing-metadata-error https://github.com/zakkak/issue-reproducers reproducer
cd reproducer
mvn package
java -agentlib:native-image-agent=config-output-dir=src/main/resources/META-INF/native-image -jar target/reproducer-1.0-SNAPSHOT.jar
mvn package
native-image -jar target/reproducer-1.0-SNAPSHOT.jar -H:+UnlockExperimentalVMOptions -H:ThrowMissingRegistrationErrors= -H:MissingRegistrationReportingMode=Exit
./reproducer-1.0-SNAPSHOT
This results in:
Hello there!
com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError: The program tried to access the resource at path
missing-test.txt
without it being registered as reachable. Add it to the resource metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources-and-resource-bundles for help
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.MissingResourceRegistrationUtils.missingResource(MissingResourceRegistrationUtils.java:43)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.Resources.createURLs(Resources.java:459)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.Resources.createURL(Resources.java:384)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.Resources.createURL(Resources.java:376)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.ResourcesHelper.nameToResourceURL(ResourcesHelper.java:103)
at [email protected]/jdk.internal.loader.BootLoader.findResource(BootLoader.java:631)
at [email protected]/java.lang.ClassLoader.getResource(ClassLoader.java:1409)
at [email protected]/java.lang.ClassLoader.getResource(ClassLoader.java:1407)
at [email protected]/java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1750)
at Main.main(Main.java:15)
at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
while I would expect it to result in:
Hello there!
Resource missing-test.txt not found!
Describe GraalVM and your environment:
- GraalVM version: GraalVM CE 21.0.2+13.1
- JDK major version: 21
- OS: Fedora 40
- Architecture: AMD64
More context:
My understanding is that the generated native images rely on the embedded resources map to throw these errors instead of a "registration" map. So if we register *.txt the native image will only know about the txt files that ended up being embedded in the native image (i.e. they were on the classpath), the current implementation can't understand that any *.txt is actually registered...
This is an issue for applications trying to load a resource that was not available at build time but can handle that case, e.g. trying to load a configuration and falling back on the default if it doesn't exist...