Skip to content

Commit 9357793

Browse files
committed
fix: Incorrect URLClassLoader initialization when url is a directory
1 parent 852512d commit 9357793

File tree

1 file changed

+10
-1
lines changed
  • buildSrc/call-site-instrumentation-plugin/src/main/java/datadog/trace/plugin/csi/util

1 file changed

+10
-1
lines changed

buildSrc/call-site-instrumentation-plugin/src/main/java/datadog/trace/plugin/csi/util/CallSiteUtils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ public static String repeat(final char value, int count) {
4747

4848
public static URL toURL(final Path path) {
4949
try {
50-
return path.toUri().toURL();
50+
URL url = path.toUri().toURL();
51+
// There's a subtle detail where `URLClassLoader` requires directory URLs to end with '/',
52+
// otherwise they are assimilated to jar file, and vice versa.
53+
if (path.toFile().isDirectory() || !path.toString().endsWith(".jar")) {
54+
String urlString = url.toString();
55+
if (!urlString.endsWith("/")) {
56+
url = new URL(urlString + "/");
57+
}
58+
}
59+
return url;
5160
} catch (MalformedURLException e) {
5261
throw new RuntimeException(e);
5362
}

0 commit comments

Comments
 (0)