Avoids NPE when installing a plugin via HTTP PUT
In Gerrit is possible to use the REST API to manage plugins, however the HTTP/PUT /plugins/myplugin.jar was failing when the plugin name specified in the MANIFEST.MF was different than the one indicated in the URI. Example: HTTP PUT http://localhost:8080/plugins/cookbook.jar resulted in NPE in InstallPlugin.java:80 because of loader.get(name) returning null. The trouble was as well that the plugin was actually installed even if the API returned 500 as the NPE happened *after* the actual plugin installation. Change-Id: Ie917f8ddfa34974c12b52cd564e40280fa9ef1cc
This commit is contained in:
@@ -60,7 +60,12 @@ class InstallPlugin implements RestModifyView<TopLevelResource, Input> {
|
||||
}
|
||||
try {
|
||||
try (InputStream in = openStream(input)) {
|
||||
loader.installPluginFromStream(name, in);
|
||||
String pluginName = loader.installPluginFromStream(name, in);
|
||||
ListPlugins.PluginInfo info =
|
||||
new ListPlugins.PluginInfo(loader.get(pluginName));
|
||||
return created
|
||||
? Response.created(info)
|
||||
: Response.ok(info);
|
||||
}
|
||||
} catch (PluginInstallException e) {
|
||||
StringWriter buf = new StringWriter();
|
||||
@@ -76,9 +81,6 @@ class InstallPlugin implements RestModifyView<TopLevelResource, Input> {
|
||||
}
|
||||
throw new BadRequestException(buf.toString());
|
||||
}
|
||||
|
||||
ListPlugins.PluginInfo info = new ListPlugins.PluginInfo(loader.get(name));
|
||||
return created ? Response.created(info) : Response.ok(info);
|
||||
}
|
||||
|
||||
private InputStream openStream(Input input)
|
||||
|
||||
@@ -157,7 +157,7 @@ public class PluginLoader implements LifecycleListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void installPluginFromStream(String originalName, InputStream in)
|
||||
public String installPluginFromStream(String originalName, InputStream in)
|
||||
throws IOException, PluginInstallException {
|
||||
checkRemoteInstall();
|
||||
|
||||
@@ -197,6 +197,8 @@ public class PluginLoader implements LifecycleListener {
|
||||
|
||||
cleanInBackground();
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
static Path asTemp(InputStream in, String prefix, String suffix, Path dir)
|
||||
|
||||
Reference in New Issue
Block a user