Skip to content

Cannot open native image resource using Path, NativeImageResourceFileSystemProvider not initialised #7682

@credmond

Description

@credmond

Describe the issue
One cannot open a resource using Java's Path. It seems NativeImageResourceFileSystemProvider is not initialised (fileSystem is null hence the exception is thrown).

Steps to reproduce the issue
Try to open any resource using this (where fortunes.json exists in /resource/fortunes.json, for example):

Path storeResourcePath = Path.of(Fortune.class.getResource("/fortunes.json").toURI());

... you will get the stacktrace provided below.

Build steps:

mvn clean compile
mvn -Pnative -Dagent exec:exec@java-agent
mvn -Pnative -Dagent package
target/fortune.exe OR ./target/fortune

E.g., using Graal's own examples @ https://github.com/graalvm/graalvm-demos/blob/master/fortune-demo/fortune/src/main/java/demo/Fortune.java, stick that line in main() and observe the same stacktrace pasted below.

It is possible to read the file this way:

InputStream stream = Fortune.class.getResource("/fortunes.json").openStream();

Obviously that's a workaround, but third party libraries using Path will still cause a problem.

I am surprised there isn't more noise about this issue.

Describe GraalVM and your environment:

  • GraalVM versions:
    Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 17.0.9+11.1 (build 17.0.9+11-LTS-jvmci-23.0-b21, mixed mode, sharing)
    Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.1+12.1 (build 21.0.1+12-jvmci-23.1-b19, mixed mode, sharing)
  • JDK major versions: 17, 21
  • OS: Windows / Linux
  • Architecture: x64

Stackrace:

Exception in thread "main" java.nio.file.FileSystemNotFoundException
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystemProvider.getFileSystem(NativeImageResourceFileSystemProvider.java:144)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystemProvider.getPath(NativeImageResourceFileSystemProvider.java:154)
        at [email protected]/java.nio.file.Path.of(Path.java:208)
        at demo.Fortune.main(Fortune.java:114)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions