Skip to content

Commit

Permalink
Apply root dir cleaning only for GraalVM native image resource scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Sep 28, 2022
1 parent 40979b2 commit 18c917c
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -738,16 +738,16 @@ protected JarFile getJarFile(String jarFileUrl) throws IOException {
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
throws IOException {


URI rootDirUri = rootDirResource.getURI();
String rootDir = rootDirUri.getRawPath();
if (!"file".equals(rootDirUri.getScheme()) && rootDir.startsWith("/")) {
rootDir = stripLeadingSlash(rootDir);
rootDir = stripTrailingSlash(rootDir);
if (rootDir.isEmpty()) {
rootDir = "/";
}
String rootDir = rootDirUri.getPath();
// If the URI is for a "resource" in the GraalVM native image file system, we have to
// ensure that the root directory does not end in a slash while simultaneously ensuring
// that the root directory is not an empty string (since fileSystem.getPath("").resolve(str)
// throws an ArrayIndexOutOfBoundsException in a native image).
if ("resource".equals(rootDirUri.getScheme()) && (rootDir.length() > 1) && rootDir.endsWith("/")) {
rootDir = rootDir.substring(0, rootDir.length() - 1);
}

FileSystem fileSystem;
try {
fileSystem = FileSystems.getFileSystem(rootDirUri.resolve("/"));
Expand Down Expand Up @@ -873,10 +873,6 @@ private static String stripLeadingSlash(String path) {
return (path.startsWith("/") ? path.substring(1) : path);
}

private static String stripTrailingSlash(String path) {
return (path.endsWith("/") ? path.substring(0, path.length() - 1) : path);
}


/**
* Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
Expand Down

0 comments on commit 18c917c

Please sign in to comment.