-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Hello there!
Describe the issue
When accessing a resource via the java module API for example via java.lang.Module#getResourceAsStream and the resource is located in a subdirectory and the resource name starts with an /, the API returns NULL instead of the InputStream for the resource.
This happens only in native-image. In JVM-Mode everything works fine.
For example:
public class Application {
public static void main(String[] args) {
InputStream resourceStream = Application.class.getModule().getResourceAsStream("/package/resource.txt");
assert resourceStream != null : "Resource is null!";
}
}will work in JVM-Mode, but not in native-image.
Removing the / at the beginning fixes the problem, but it should also work with the / in the path.
Steps to reproduce the issue
- Clone repository at https://github.com/Rottinator/graalvm-module-sample.
- Build the project via
docker build -t graalvm-module-sample . - Run the JVM-Version via:
docker run --rm graalvm-module-sample java --module-path /code/target/graalvm-module-sample-1.0-SNAPSHOT.jar --module graalvmmodulesample/de.example.graalvmmodulesample.Application - Run the native-image-Version via:
docker run --rm graalvm-module-sample
Both versions should have the same output, but the native-image version fails, while loading the resource via module API.
Describe GraalVM and your environment:
- Tried it with 22.2.0 Java 17 and also with latest dev build
- OS: Happens on Windows and Linux
- Architecture: ** AMD64**
This issue was already discussed in the native-image slack channel at https://graalvm.slack.com/archives/CN9KSFB40/p1664480047678039 and was identified as bug from @olpaw
Best regards
Christoph