Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-41420] Native Image FileSystem throws exception when resolving against an empty Path #5081

Closed
sbrannen opened this issue Sep 26, 2022 · 3 comments · Fixed by #5107
Closed
Assignees
Labels
bug native-image spring spring related issue

Comments

@sbrannen
Copy link

sbrannen commented Sep 26, 2022

Overview

As stated in #5020 (comment) and #5020 (comment), if you invoke fileSystem.getPath("") against the native image FileSystem and then invoke resolve(...) on that Path, you get the following exception.

java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 0
       com.oracle.svm.core.jdk.resources.NativeImageResourcePath.resolve(NativeImageResourcePath.java:302)
       com.oracle.svm.core.jdk.resources.NativeImageResourcePath.resolve(NativeImageResourcePath.java:327)

Whereas, a Path created by the standard OS FileSystem does not throw an exception in that scenario.

For example...

System.out.println("FileSystems.getDefault().getPath(\"\"): [%s]".formatted(FileSystems.getDefault().getPath("")));
System.out.println("FileSystems.getDefault().getPath(\"\").resolve(\"test\"): [%s]".formatted(FileSystems.getDefault().getPath("").resolve("test")));

... the above code prints the following on the JVM as well as within a native image.

FileSystems.getDefault().getPath(""): []
FileSystems.getDefault().getPath("").resolve("test"): [test]

Whereas, when executing the following within a native image...

URI root = new URI("resource:/");
FileSystem nativeImageFileSystem = FileSystems.newFileSystem(root, Map.of());

System.out.println("nativeImageFileSystem.getPath(\"\"): [%s]".formatted(nativeImageFileSystem.getPath("")));
System.out.println("nativeImageFileSystem.getPath(\"\").resolve(\"test\"): [%s]".formatted(nativeImageFileSystem.getPath("").resolve("test")));

... that prints:

nativeImageFileSystem.getPath(""): []

... and then throws the aforementioned ArrayIndexOutOfBoundsException.

Cause of the exception

In the following line of code...

... if p1.path.length is 0, then you get the ArrayIndexOutOfBoundsException.

System Tested

  • GraalVM: OpenJDK Runtime Environment GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06)
  • Mac OS: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64
@jovanstevanovic
Copy link
Member

Fix is on a master.

@sbrannen
Copy link
Author

sbrannen commented Oct 10, 2022

Fix is on a master.

Great! 👍

@fniephaus and @vjovanov, is there any way to have related commits automatically linked to the corresponding GitHub issue?

For example, I would like to see the commit(s) associated with the fix, but I don't know how to find them (at least not easily).

It looks like this is the commit: 3816914

So it would be great if commit messages would include the related GitHub issue(s) (like #5081 or gh-5081).

@fniephaus fniephaus changed the title Native Image FileSystem throws exception when resolving against an empty Path [GR-41420] Native Image FileSystem throws exception when resolving against an empty Path Oct 11, 2022
@fniephaus
Copy link
Member

@fniephaus and @vjovanov, is there any way to have related commits automatically linked to the corresponding GitHub issue?

Thanks for the feedback, @sbrannen. Typically, we add the internal tracking code (e.g., GR-41420) as a prefix to the GitHub issue and then there is going to be a merge with the fix matching that prefix (@jovanstevanovic is a relatively new team member and doesn't know all these details yet, I took care of it just now). I understand this situation is not ideal and GitHub provides different ways to connect issues, commits, and PRs. Although I'm glad that our CI system is smart enough to automate a lot of things for us behind the curtain, it's not yet smart enough to take advantages of those GitHub features but we're working on it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment