Replace "new URLClassLoader" with newInstance calls

Change-Id: Id402ea839e9a9bbd4c67a8d800afb9aedaeecdb0
This commit is contained in:
Maxime Guerreiro 2018-04-16 13:13:37 +00:00
parent d620ad1043
commit f04f3555ef
4 changed files with 7 additions and 6 deletions

View File

@ -305,9 +305,9 @@ public final class GerritLauncher {
ClassLoader parent = ClassLoader.getSystemClassLoader();
if (!extapi.isEmpty()) {
parent = new URLClassLoader(extapi.toArray(new URL[extapi.size()]), parent);
parent = URLClassLoader.newInstance(extapi.toArray(new URL[extapi.size()]), parent);
}
return new URLClassLoader(jars.values().toArray(new URL[jars.size()]), parent);
return URLClassLoader.newInstance(jars.values().toArray(new URL[jars.size()]), parent);
}
private static void extractJar(ZipFile zf, ZipEntry ze, SortedMap<String, URL> jars)
@ -718,7 +718,7 @@ public final class GerritLauncher {
dirs.add(u);
}
}
return new URLClassLoader(
return URLClassLoader.newInstance(
dirs.toArray(new URL[dirs.size()]), ClassLoader.getSystemClassLoader().getParent());
}

View File

@ -66,7 +66,7 @@ public class InitPluginStepsLoader {
private InitStep loadInitStep(Path jar) {
try {
URLClassLoader pluginLoader =
new URLClassLoader(
URLClassLoader.newInstance(
new URL[] {jar.toUri().toURL()}, InitPluginStepsLoader.class.getClassLoader());
try (JarFile jarFile = new JarFile(jar.toFile())) {
Attributes jarFileAttributes = jarFile.getManifest().getMainAttributes();

View File

@ -136,7 +136,8 @@ public class JarPluginProvider implements ServerPluginProvider {
urls.add(tmp.toUri().toURL());
ClassLoader pluginLoader =
new URLClassLoader(urls.toArray(new URL[urls.size()]), PluginUtil.parentFor(type));
URLClassLoader.newInstance(
urls.toArray(new URL[urls.size()]), PluginUtil.parentFor(type));
JarScanner jarScanner = createJarScanner(tmp);
PluginConfig pluginConfig = configFactory.getFromGerritConfig(name);

View File

@ -175,7 +175,7 @@ public class RulesCache {
Path jarPath = rulesDir.resolve("rules-" + rulesId.getName() + ".jar");
if (Files.isRegularFile(jarPath)) {
URL[] cp = new URL[] {toURL(jarPath)};
return save(newEmptyMachine(new URLClassLoader(cp, systemLoader)));
return save(newEmptyMachine(URLClassLoader.newInstance(cp, systemLoader)));
}
}