From c80b8b71112864a7a6b77baac151eca690b60cd3 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 26 Sep 2016 10:50:24 +0200 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. --- .../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 fba3fd529dcf0..ac21256acaa70 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 @@ protected void execute(Terminal terminal, OptionSet options, Map // 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 af1f311dd23d6..6b930c171116e 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 @@ void assertInstallCleaned(Environment env) throws IOException { } } + 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);