@@ -738,16 +738,16 @@ protected JarFile getJarFile(String jarFileUrl) throws IOException {
738
738
protected Set <Resource > doFindPathMatchingFileResources (Resource rootDirResource , String subPattern )
739
739
throws IOException {
740
740
741
-
742
741
URI rootDirUri = rootDirResource .getURI ();
743
- String rootDir = rootDirUri .getRawPath ();
744
- if (! "file" . equals ( rootDirUri . getScheme ()) && rootDir . startsWith ( "/" )) {
745
- rootDir = stripLeadingSlash ( rootDir );
746
- rootDir = stripTrailingSlash ( rootDir );
747
- if ( rootDir . isEmpty ()) {
748
- rootDir = "/" ;
749
- }
742
+ String rootDir = rootDirUri .getPath ();
743
+ // If the URI is for a "resource" in the GraalVM native image file system, we have to
744
+ // ensure that the root directory does not end in a slash while simultaneously ensuring
745
+ // that the root directory is not an empty string (since fileSystem.getPath("").resolve(str)
746
+ // throws an ArrayIndexOutOfBoundsException in a native image).
747
+ if ( "resource" . equals ( rootDirUri . getScheme ()) && ( rootDir . length () > 1 ) && rootDir . endsWith ( "/" )) {
748
+ rootDir = rootDir . substring ( 0 , rootDir . length () - 1 );
750
749
}
750
+
751
751
FileSystem fileSystem ;
752
752
try {
753
753
fileSystem = FileSystems .getFileSystem (rootDirUri .resolve ("/" ));
@@ -873,10 +873,6 @@ private static String stripLeadingSlash(String path) {
873
873
return (path .startsWith ("/" ) ? path .substring (1 ) : path );
874
874
}
875
875
876
- private static String stripTrailingSlash (String path ) {
877
- return (path .endsWith ("/" ) ? path .substring (0 , path .length () - 1 ) : path );
878
- }
879
-
880
876
881
877
/**
882
878
* Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
0 commit comments