Skip to content

Commit 6238164

Browse files
committed
org.apache.commons.cli.Option.processValue(String) should throw
IllegalStateException instead of IllegalArgumentException The method throws the exception if the state is wrong, not if the argument is
1 parent 91f3acf commit 6238164

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<action type="fix" issue="CLI-344" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory">Fail faster with a more precise NullPointerException: DefaultParser.parse() throws NullPointerException when options parameter is null.</action>
4040
<action type="fix" issue="CLI-347" dev="ggregory" due-to="Ruiqi Dong, Gary Gregory">Options.addOptionGroup(OptionGroup) does not remove required options from requiredOpts list.</action>
4141
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.cli.Option.Builder.get() should throw IllegalStateException instead of IllegalArgumentException.</action>
42+
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.cli.Option.processValue(String) should throw IllegalStateException instead of IllegalArgumentException.</action>
4243
<!-- ADD -->
4344
<action type="add" issue="CLI-339" dev="ggregory" due-to="Claude Warren, Gary Gregory">Help formatter extension in the new package #314.</action>
4445
<action type="add" dev="ggregory" due-to="Gary Gregory">CommandLine.Builder implements Supplier&lt;CommandLine&gt;.</action>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ public boolean isRequired() {
840840
*/
841841
void processValue(final String value) {
842842
if (argCount == UNINITIALIZED) {
843-
throw new IllegalArgumentException("NO_ARGS_ALLOWED");
843+
throw new IllegalStateException("NO_ARGS_ALLOWED");
844844
}
845845
String add = Objects.requireNonNull(value, "value");
846846
// this Option has a separator character

src/test/java/org/apache/commons/cli/OptionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private Option roundTrip(final Option o) throws IOException, ClassNotFoundExcept
104104
void testAddValue() {
105105
final Option option = new Option("f", null);
106106
assertThrows(UnsupportedOperationException.class, () -> option.addValue(""));
107-
assertThrows(IllegalArgumentException.class, () -> option.processValue(""));
107+
assertThrows(IllegalStateException.class, () -> option.processValue(""));
108108
}
109109

110110
@Test

0 commit comments

Comments
 (0)