This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new 62381649 org.apache.commons.cli.Option.processValue(String) should 
throw IllegalStateException instead of IllegalArgumentException
62381649 is described below

commit 62381649140baadc331a814bd12d301afef02e37
Author: Gary D. Gregory <[email protected]>
AuthorDate: Tue Jul 29 13:24:46 2025 -0400

    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
---
 src/changes/changes.xml                              | 1 +
 src/main/java/org/apache/commons/cli/Option.java     | 2 +-
 src/test/java/org/apache/commons/cli/OptionTest.java | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3d4a8034..6f79f100 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -39,6 +39,7 @@
       <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>
       <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>
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">org.apache.commons.cli.Option.Builder.get() should throw 
IllegalStateException instead of IllegalArgumentException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary 
Gregory">org.apache.commons.cli.Option.processValue(String) should throw 
IllegalStateException instead of IllegalArgumentException.</action>
       <!-- ADD -->
       <action type="add" issue="CLI-339" dev="ggregory" due-to="Claude Warren, 
Gary Gregory">Help formatter extension in the new package #314.</action>
       <action type="add" dev="ggregory" due-to="Gary 
Gregory">CommandLine.Builder implements Supplier&lt;CommandLine&gt;.</action>
diff --git a/src/main/java/org/apache/commons/cli/Option.java 
b/src/main/java/org/apache/commons/cli/Option.java
index f8784c94..aac02d78 100644
--- a/src/main/java/org/apache/commons/cli/Option.java
+++ b/src/main/java/org/apache/commons/cli/Option.java
@@ -840,7 +840,7 @@ public class Option implements Cloneable, Serializable {
      */
     void processValue(final String value) {
         if (argCount == UNINITIALIZED) {
-            throw new IllegalArgumentException("NO_ARGS_ALLOWED");
+            throw new IllegalStateException("NO_ARGS_ALLOWED");
         }
         String add = Objects.requireNonNull(value, "value");
         // this Option has a separator character
diff --git a/src/test/java/org/apache/commons/cli/OptionTest.java 
b/src/test/java/org/apache/commons/cli/OptionTest.java
index fbdb898f..6780eb2c 100644
--- a/src/test/java/org/apache/commons/cli/OptionTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionTest.java
@@ -104,7 +104,7 @@ class OptionTest {
     void testAddValue() {
         final Option option = new Option("f", null);
         assertThrows(UnsupportedOperationException.class, () -> 
option.addValue(""));
-        assertThrows(IllegalArgumentException.class, () -> 
option.processValue(""));
+        assertThrows(IllegalStateException.class, () -> 
option.processValue(""));
     }
 
     @Test

Reply via email to