Don't always close URLClassLoaders in InitPluginStepsLoader

Similar like it is done by commit 6a88c2fcb8
the URLClassLoader should not be closed since closing it means that it can
no longer be used to load new classes or resources that are defined by this
loader.

This partially reverts commit 21e277760e.

Change-Id: I57952fbf7a94eff9563fb205b42d86545fc3ff8a
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2014-02-25 08:56:53 +01:00
committed by David Pursehouse
parent 6a88c2fcb8
commit d20a20ce94

View File

@@ -65,26 +65,28 @@ public class InitPluginStepsLoader {
return pluginsInitSteps;
}
@SuppressWarnings("resource")
private InitStep loadInitStep(File jar) {
try (URLClassLoader pluginLoader =
new URLClassLoader(new URL[] {jar.toURI().toURL()},
InitPluginStepsLoader.class.getClassLoader());
JarFile jarFile = new JarFile(jar);) {
Attributes jarFileAttributes = jarFile.getManifest().getMainAttributes();
String initClassName = jarFileAttributes.getValue("Gerrit-InitStep");
if (initClassName == null) {
try {
URLClassLoader pluginLoader =
new URLClassLoader(new URL[] {jar.toURI().toURL()},
InitPluginStepsLoader.class.getClassLoader());
try (JarFile jarFile = new JarFile(jar)) {
Attributes jarFileAttributes = jarFile.getManifest().getMainAttributes();
String initClassName = jarFileAttributes.getValue("Gerrit-InitStep");
if (initClassName == null) {
return null;
}
@SuppressWarnings("unchecked")
Class<? extends InitStep> initStepClass =
(Class<? extends InitStep>) pluginLoader.loadClass(initClassName);
return getPluginInjector(jar).getInstance(initStepClass);
} catch (ClassCastException e) {
ui.message(
"WARN: InitStep from plugin %s does not implement %s (Exception: %s)",
jar.getName(), InitStep.class.getName(), e.getMessage());
return null;
}
@SuppressWarnings("unchecked")
Class<? extends InitStep> initStepClass =
(Class<? extends InitStep>) pluginLoader.loadClass(initClassName);
return getPluginInjector(jar).getInstance(initStepClass);
} catch (ClassCastException e) {
ui.message(
"WARN: InitStep from plugin %s does not implement %s (Exception: %s)",
jar.getName(), InitStep.class.getName(), e.getMessage());
return null;
} catch (Exception e) {
ui.message(
"WARN: Cannot load and get plugin init step for %s (Exception: %s)",