You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by su...@apache.org on 2015/02/13 03:17:16 UTC
[02/47] knox git commit: KNOX-501: Avoid NPE ,
in case of passing invalid argument to KnoxCli. Contributed by
J.Andreina.
KNOX-501: Avoid NPE , in case of passing invalid argument to KnoxCli.
Contributed by J.Andreina.
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/7d839171
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/7d839171
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/7d839171
Branch: refs/heads/KNOX-481
Commit: 7d839171a7c2ecda217732718ae5aedf4d429fba
Parents: 2192932
Author: Kevin Minder <ke...@hortonworks.com>
Authored: Thu Feb 12 10:40:26 2015 -0500
Committer: Kevin Minder <ke...@hortonworks.com>
Committed: Thu Feb 12 10:40:26 2015 -0500
----------------------------------------------------------------------
CHANGES | 1 +
.../java/org/apache/hadoop/gateway/util/KnoxCLI.java | 8 +++++---
.../java/org/apache/hadoop/gateway/util/KnoxCLITest.java | 11 +++++++++++
3 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/7d839171/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 4d072b6..9f2677a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,7 @@ Release Notes - Apache Knox - Version 0.6.0
** Improvement
* [KNOX-462] - Proper error message when root tag of topology file incorrect
+ * [KNOX-501] - Avoid NPE in case of passing invalid argument to KnoxCli.
------------------------------------------------------------------------------
Release Notes - Apache Knox - Version 0.5.1
http://git-wip-us.apache.org/repos/asf/knox/blob/7d839171/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
index dd379aa..8366f2e 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/util/KnoxCLI.java
@@ -89,10 +89,12 @@ public class KnoxCLI extends Configured implements Tool {
if (exitCode != 0) {
return exitCode;
}
- if (command.validate()) {
- initializeServices( command instanceof MasterCreateCommand );
- command.execute();
+ if (command != null && command.validate()) {
+ initializeServices( command instanceof MasterCreateCommand );
+ command.execute();
} else {
+ out.println("ERROR: Invalid Command" + "\n" + "Unrecognized option:" + args[0] + "\n"
+ + "A fatal exception has occurred. Program will exit.");
exitCode = -2;
}
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/knox/blob/7d839171/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java b/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java
index 82fc9cc..82f380a 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/util/KnoxCLITest.java
@@ -120,6 +120,17 @@ public class KnoxCLITest {
}
@Test
+ public void testForInvalidArgument() throws Exception {
+ outContent.reset();
+ String[] args1 = { "--value", "testvalue1", "--master", "master" };
+ KnoxCLI cli = new KnoxCLI();
+ cli.setConf(new GatewayConfigImpl());
+ int rc = cli.run(args1);
+ assertEquals(-2, rc);
+ assertTrue(outContent.toString().contains("ERROR: Invalid Command"));
+ }
+
+ @Test
public void testListAndDeleteOfAliasForValidClusterName() throws Exception {
outContent.reset();
String[] args1 =