File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
buildSrc/call-site-instrumentation-plugin/src/main/java/datadog/trace/plugin/csi/util Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 33import java .io .File ;
44import java .net .MalformedURLException ;
55import java .net .URL ;
6+ import java .nio .file .Files ;
67import java .nio .file .Path ;
78import java .util .stream .Collectors ;
89import java .util .stream .IntStream ;
@@ -48,9 +49,14 @@ public static String repeat(final char value, int count) {
4849 public static URL toURL (final Path path ) {
4950 try {
5051 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" )) {
52+ // URLClassLoader interprets URLs ending with '/' as directories. If the trailing '/' is missing,
53+ // a directory URL is treated as a JAR. If the path does yet exist on disk assumes that paths
54+ // not ending with ".jar" are directories.
55+ boolean shouldAddSlash = Files .exists (path ) ?
56+ Files .isDirectory (path ) :
57+ !path .toString ().endsWith (".jar" );
58+
59+ if (shouldAddSlash ) {
5460 String urlString = url .toString ();
5561 if (!urlString .endsWith ("/" )) {
5662 url = new URL (urlString + "/" );
You can’t perform that action at this time.
0 commit comments