Skip to content

Commit

Permalink
Let JarFileLocation work with custom ClassLoader URIs.
Browse files Browse the repository at this point in the history
Some ClassLoaders that work with repackaged JAR files return custom resource URIs to indicate custom class loading locations. For example, the ClassLoader in a packaged Spring Boot's returns the following URI for source package named example: jar:file:/Path/to/my.jar!/BOOT-INF/classes!/example/. Note the second "!/" to indicate a classpath root.

Prior to this commit, JarFileLocation was splitting paths to a resource at the first "!/" assuming the remainder of the string would depict the actual resource path. That remainder potentially containing a further "!/" would prevent the JAR entry matching in FromJar.classFilesBeneath(…) as the entries themselves do not contain the exclamation mark.

This commit changes the treatment of the URI in JarFileLocation to rather use the *last* "!/" as splitting point so that the remainder is a proper path within the ClassLoader and the matching in FromJar.classFilesBeneath(…) works properly.

Signed-off-by: Oliver Drotbohm <odrotbohm@vmware.com>
  • Loading branch information
odrotbohm committed Jul 4, 2023
1 parent 5fbb9f7 commit 2a8d3f7
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ private static URI newJarUri(URI uri) {
@Override
ClassFileSource asClassFileSource(ImportOptions importOptions) {
try {
String[] parts = uri.toString().split("!/", 2);
String uriString = uri.toString();
int index = uriString.lastIndexOf("!/");
String[] parts = { uriString.substring(0, index), uriString.substring(index + 2) };
return new ClassFileSource.FromJar(new URL(parts[0] + "!/"), parts[1], importOptions);
} catch (IOException e) {
throw new LocationException(e);
Expand Down

0 comments on commit 2a8d3f7

Please sign in to comment.