[
https://issues.apache.org/jira/browse/HDFS-6796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14081695#comment-14081695
]
Tsz Wo Nicholas Sze commented on HDFS-6796:
-------------------------------------------
Let's also add some meaningful error messages. The first checkArgument(..) can
be replaced by checkArgument(..) in each individual case as below.
{code}
+++
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/Balancer.java
(working copy)
@@ -1691,9 +1691,9 @@
if (args != null) {
try {
for(int i = 0; i < args.length; i++) {
- checkArgument(args.length >= 2, "args = " + Arrays.toString(args));
if ("-threshold".equalsIgnoreCase(args[i])) {
- i++;
+ checkArgument(++i == args.length,
+ "Threshold value is missing: args = " +
Arrays.toString(args));
try {
threshold = Double.parseDouble(args[i]);
if (threshold < 1 || threshold > 100) {
@@ -1708,7 +1708,8 @@
throw e;
}
} else if ("-policy".equalsIgnoreCase(args[i])) {
- i++;
+ checkArgument(++i == args.length,
+ "Policy value is missing: args = " + Arrays.toString(args));
try {
policy = BalancingPolicy.parse(args[i]);
} catch(IllegalArgumentException e) {
...
{code}
> Improving the argument check during balancer command line parsing
> -----------------------------------------------------------------
>
> Key: HDFS-6796
> URL: https://issues.apache.org/jira/browse/HDFS-6796
> Project: Hadoop HDFS
> Issue Type: Bug
> Components: balancer
> Affects Versions: 2.4.1
> Reporter: Benoy Antony
> Assignee: Benoy Antony
> Attachments: HDFS-6796.patch
>
>
> Currently balancer CLI parser simply checks if the total number of arguments
> is greater than 2 inside the loop. Since the check does not include any loop
> variables, it is not a proper check when there more than 2 arguments.
--
This message was sent by Atlassian JIRA
(v6.2#6252)