Use EMPTY_STRING_ARRAY constant. (#102)
diff --git a/src/main/java/org/apache/commons/cli/CommandLine.java b/src/main/java/org/apache/commons/cli/CommandLine.java
index 333ef9d..05d6a93 100644
--- a/src/main/java/org/apache/commons/cli/CommandLine.java
+++ b/src/main/java/org/apache/commons/cli/CommandLine.java
@@ -25,6 +25,8 @@
import java.util.List;
import java.util.Properties;
+import static org.apache.commons.cli.Util.EMPTY_STRING_ARRAY;
+
/**
* Represents list of arguments parsed against a {@link Options} descriptor.
* <p>
@@ -328,7 +330,7 @@
}
}
- return values.isEmpty() ? null : values.toArray(new String[values.size()]);
+ return values.isEmpty() ? null : values.toArray(EMPTY_STRING_ARRAY);
}
/**
diff --git a/src/main/java/org/apache/commons/cli/Option.java b/src/main/java/org/apache/commons/cli/Option.java
index 616c112..d101c50 100644
--- a/src/main/java/org/apache/commons/cli/Option.java
+++ b/src/main/java/org/apache/commons/cli/Option.java
@@ -22,6 +22,8 @@
import java.util.List;
import java.util.Objects;
+import static org.apache.commons.cli.Util.EMPTY_STRING_ARRAY;
+
/**
* Describes a single command-line option. It maintains information regarding the short-name of the option, the
* long-name, if any exists, a flag indicating if an argument is required for this option, and a self-documenting
@@ -617,7 +619,7 @@
* @return the values of this Option as a String array or null if there are no values
*/
public String[] getValues() {
- return hasNoValues() ? null : values.toArray(new String[values.size()]);
+ return hasNoValues() ? null : values.toArray(EMPTY_STRING_ARRAY);
}
/**