Skip to content

Commit 16f82db

Browse files
committed
chore: Readability of CallSiteUtils::toURL
1 parent b5ef0ba commit 16f82db

File tree

1 file changed

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

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.net.MalformedURLException;
55
import java.net.URL;
6+
import java.nio.file.Files;
67
import java.nio.file.Path;
78
import java.util.stream.Collectors;
89
import 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 + "/");

0 commit comments

Comments
 (0)