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 a8e61aef org.apache.commons.cli.OptionBuilder.create() should throw
IllegalStateException instead of IllegalArgumentException
a8e61aef is described below
commit a8e61aef86e5ec510a46c709ea2fd71fbf6ca490
Author: Gary D. Gregory <[email protected]>
AuthorDate: Tue Jul 29 13:26:32 2025 -0400
org.apache.commons.cli.OptionBuilder.create() should throw
IllegalStateException instead of IllegalArgumentException
Is the state that's wrong, there are no arguments to validate anyway.
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/cli/OptionBuilder.java | 2 +-
src/test/java/org/apache/commons/cli/OptionBuilderTest.java | 4 ++--
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6f79f100..f9a82dd6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -40,6 +40,7 @@
<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>
+ <action type="fix" dev="ggregory" due-to="Gary
Gregory">org.apache.commons.cli.OptionBuilder.create() 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<CommandLine>.</action>
diff --git a/src/main/java/org/apache/commons/cli/OptionBuilder.java
b/src/main/java/org/apache/commons/cli/OptionBuilder.java
index 2d44ff02..41ff9b63 100644
--- a/src/main/java/org/apache/commons/cli/OptionBuilder.java
+++ b/src/main/java/org/apache/commons/cli/OptionBuilder.java
@@ -72,7 +72,7 @@ public final class OptionBuilder {
public static Option create() throws IllegalArgumentException {
if (longOption == null) {
reset();
- throw new IllegalArgumentException("must specify longopt");
+ throw new IllegalStateException("must specify longopt");
}
return create(null);
diff --git a/src/test/java/org/apache/commons/cli/OptionBuilderTest.java
b/src/test/java/org/apache/commons/cli/OptionBuilderTest.java
index 39c7e713..26233f7a 100644
--- a/src/test/java/org/apache/commons/cli/OptionBuilderTest.java
+++ b/src/test/java/org/apache/commons/cli/OptionBuilderTest.java
@@ -50,7 +50,7 @@ class OptionBuilderTest {
void testBuilderIsResettedAlways() {
assertThrows(IllegalArgumentException.class, () ->
OptionBuilder.withDescription("JUnit").create('"'));
assertNull(OptionBuilder.create('x').getDescription(), "we inherited a
description");
- assertThrows(IllegalArgumentException.class, (Executable)
OptionBuilder::create);
+ assertThrows(IllegalStateException.class, (Executable)
OptionBuilder::create);
assertNull(OptionBuilder.create('x').getDescription(), "we inherited a
description");
}
@@ -77,7 +77,7 @@ class OptionBuilderTest {
@Test
void testCreateIncompleteOption() {
- assertThrows(IllegalArgumentException.class, (Executable)
OptionBuilder::create);
+ assertThrows(IllegalStateException.class, (Executable)
OptionBuilder::create);
// implicitly reset the builder
OptionBuilder.create("opt");
}