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>
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 b982787..4a4dc92 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 @@
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 @@
}
};
return Class.forName(klass.getName(), true, testClassLoader);
- } catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException | MalformedURLException e) {
throw new InitializationError(e);
}
}