summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit/src/org/eclipse/jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2020-12-26 02:28:03 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-02-05 19:45:49 -0500
commit9299df41cb941ab21b6c4bd835510305b7fd5382 (patch)
tree61e4b0fd87823785117d96e7c1eed0dad5c918d2 /org.eclipse.jgit.junit/src/org/eclipse/jgit
parentc2990810e9c50ef78f116ffcb2a55a24cdcc6e0c (diff)
downloadjgit-9299df41cb941ab21b6c4bd835510305b7fd5382.tar.gz
jgit-9299df41cb941ab21b6c4bd835510305b7fd5382.zip
Fix SeparateClassloaderTestRunner on Java 9 or higher
Since Java 9 the SystemClassLoader is no longer a URLClassLoader. Change-Id: I3aa834f1075e611c86fc4684fda6a50c684b3729 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.junit/src/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java
index b982787e75..4a4dc92c43 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/SeparateClassloaderTestRunner.java
@@ -9,10 +9,10 @@
*/
package org.eclipse.jgit.junit;
-import static java.lang.ClassLoader.getSystemClassLoader;
-
+import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.nio.file.Paths;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
@@ -40,7 +40,13 @@ public class SeparateClassloaderTestRunner extends BlockJUnit4ClassRunner {
private static Class<?> loadNewClass(Class<?> klass)
throws InitializationError {
try {
- URL[] urls = ((URLClassLoader) getSystemClassLoader()).getURLs();
+ String pathSeparator = System.getProperty("path.separator");
+ String[] classPathEntries = System.getProperty("java.class.path")
+ .split(pathSeparator);
+ URL[] urls = new URL[classPathEntries.length];
+ for (int i = 0; i < classPathEntries.length; i++) {
+ urls[i] = Paths.get(classPathEntries[i]).toUri().toURL();
+ }
ClassLoader testClassLoader = new URLClassLoader(urls) {
@Override
@@ -54,7 +60,7 @@ public class SeparateClassloaderTestRunner extends BlockJUnit4ClassRunner {
}
};
return Class.forName(klass.getName(), true, testClassLoader);
- } catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException | MalformedURLException e) {
throw new InitializationError(e);
}
}