Skip to content

Commit 4169b28

Browse files
committed
Revamp classpath search to use normalized paths
On Windows with Java 11, the `java.class.path` property contains backslash-escaped backslashes, as in "`C:\\foo\\bar`". These doubled backslashes interfere with the logic for finding classpath entries that contain the requested element. Using normalized paths for all comparisons seems to fix the problem, and will likely be more robust in general.
1 parent 777303c commit 4169b28

File tree

1 file changed

+18
-17
lines changed
  • com.ibm.wala.core/src/testFixtures/java/com/ibm/wala/core/tests/util

1 file changed

+18
-17
lines changed

com.ibm.wala.core/src/testFixtures/java/com/ibm/wala/core/tests/util/WalaTestCase.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import com.ibm.wala.ssa.SSAOptions;
1717
import com.ibm.wala.util.heapTrace.HeapTracer;
1818
import java.io.File;
19+
import java.nio.file.Paths;
20+
import java.util.Arrays;
21+
import java.util.stream.Collectors;
1922
import org.junit.After;
2023
import org.junit.Before;
2124
import org.junit.runner.JUnitCore;
@@ -63,22 +66,20 @@ protected static void justThisTest(Class<?> testClass) {
6366
}
6467

6568
protected static String getClasspathEntry(String elt) {
66-
StringBuilder result = null;
67-
for (String s : System.getProperty("java.class.path").split(File.pathSeparator)) {
68-
if (s.contains(elt)) {
69-
File e = new File(s);
70-
assert e.exists() : elt + " expected to exist";
71-
if (e.isDirectory() && !s.endsWith("/")) {
72-
s += '/';
73-
}
74-
if (result == null) {
75-
result = new StringBuilder(s);
76-
} else {
77-
result.append(File.pathSeparator).append(s);
78-
}
79-
}
80-
}
81-
assert result != null : "cannot find " + elt;
82-
return result.toString();
69+
final String normalizedElt = Paths.get(elt).normalize().toString();
70+
final String result =
71+
Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator))
72+
.map(candidate -> Paths.get(candidate).normalize())
73+
.filter(candidate -> candidate.toString().contains(normalizedElt))
74+
.map(
75+
found -> {
76+
final String foundString = found.toString();
77+
return found.toFile().isDirectory()
78+
? foundString + File.separatorChar
79+
: foundString;
80+
})
81+
.collect(Collectors.joining(File.pathSeparator));
82+
assert !result.isEmpty() : "cannot find " + elt;
83+
return result;
8384
}
8485
}

0 commit comments

Comments
 (0)