Remove classloading-related code that was specific to Java 8
@@ -21,6 +21,7 @@ package org.sosy_lab.java_smt;
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.lang.reflect.Constructor;
@@ -28,11 +29,8 @@ import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
-import java.net.URLClassLoader;
import java.net.URLConnection;
-import java.util.ArrayList;
import java.util.LinkedHashSet;
-import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -334,20 +332,12 @@ public class SolverContextFactory {
// The new class loader needs to be able to load classes from all the packages in Z3_CLASSES,
// and for this it needs the URLs for both the JavaSMT and Z3 libs.
- if (parentClassLoader instanceof URLClassLoader) {
- // Up to Java 8, we can easily get all URLs from the current class loader,
- // which includes the required URLs.
- @SuppressWarnings("resource")
- URLClassLoader uParentClassLoader = (URLClassLoader) parentClassLoader;
- builder.setUrls(uParentClassLoader.getURLs());
+ final ImmutableList.Builder<URL> libs = ImmutableList.builderWithExpectedSize(2);
- } else {
- // From Java 9 on, the class loader is no longer a URLClassLoader.
- // We need to manually get the URL for the JavaSMT lib (easy),
- // and for Z3 (more complex, because we do not actually want to load a class from it).
- final List<URL> libs = new ArrayList<>(2);
+ // We need to manually get the URL for the JavaSMT lib (easy) ...
libs.add(SolverContextFactory.class.getProtectionDomain().getCodeSource().getLocation());
+ // .... and for Z3 (more complex, because we do not actually want to load a class from it).
final URL z3Class = parentClassLoader.getResource("com/microsoft/z3/Native.class");
if (z3Class == null) {
// Z3 cannot be found in the current class loader.
@@ -382,8 +372,7 @@ public class SolverContextFactory {
}
}
- builder.setUrls(libs);
- }
+ builder.setUrls(libs.build());
return builder.build();
}
