From a6e33494abe573338b71c2b370abd927648a69c4 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 26 Sep 2016 08:09:15 -0400 Subject: [PATCH] Provide error message when plugin id is missing Today when executing the install plugin command without a plugin id, we end up throwing an NPE because the plugin id is null yet we just keep going (ultimatley we try to lookup the null plugin id in a set, the direct cause of the NPE). This commit modifies the install command so that a missing plugin id is detected and help is provided to the user. Relates #20660 --- .../org/elasticsearch/plugins/InstallPluginCommand.java | 3 +++ .../elasticsearch/plugins/InstallPluginCommandTests.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java index fba3fd529dc..ac21256acaa 100644 --- a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java +++ b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java @@ -192,6 +192,9 @@ class InstallPluginCommand extends SettingCommand { // pkg private for testing void execute(Terminal terminal, String pluginId, boolean isBatch, Map settings) throws Exception { + if (pluginId == null) { + throw new UserException(ExitCodes.USAGE, "plugin id is required"); + } final Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, terminal, settings); // TODO: remove this leniency!! is it needed anymore? if (Files.exists(env.pluginsFile()) == false) { diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java index af1f311dd23..6b930c17111 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/InstallPluginCommandTests.java @@ -291,6 +291,12 @@ public class InstallPluginCommandTests extends ESTestCase { } } + public void testMissingPluginId() throws IOException { + final Tuple env = createEnv(fs, temp); + final UserException e = expectThrows(UserException.class, () -> installPlugin(null, env.v1())); + assertTrue(e.getMessage(), e.getMessage().contains("plugin id is required")); + } + public void testSomethingWorks() throws Exception { Tuple env = createEnv(fs, temp); Path pluginDir = createPluginDir(temp);