Skip to content

Commit bd39a1c

Browse files
Use empty array. (apache#61)
1 parent d63b4bd commit bd39a1c

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/main/java/org/apache/commons/cli/GnuParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ protected String[] flatten(final Options options, final String[] arguments, fina
8585
}
8686
}
8787

88-
return tokens.toArray(new String[tokens.size()]);
88+
return tokens.toArray(Util.EMPTY_STRING_ARRAY);
8989
}
9090
}

src/main/java/org/apache/commons/cli/PosixParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ else if (token.startsWith("-")) {
176176
gobble(iter);
177177
}
178178

179-
return tokens.toArray(new String[tokens.size()]);
179+
return tokens.toArray(Util.EMPTY_STRING_ARRAY);
180180
}
181181

182182
/**

src/main/java/org/apache/commons/cli/Util.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2121
* Contains useful helper methods for classes within this package.
2222
*/
2323
final class Util {
24+
25+
/**
26+
* An empty immutable {@code String} array.
27+
*/
28+
static final String[] EMPTY_STRING_ARRAY = new String[0];
29+
2430
/**
2531
* Remove the leading and trailing quotes from {@code str}. E.g. if str is '"one two"', then 'one two' is returned.
2632
*

0 commit comments

Comments
 (0)