Skip to content

Commit a8e61ae

Browse files
committed
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.
1 parent 6238164 commit a8e61ae

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
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>
4242
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.cli.Option.processValue(String) should throw IllegalStateException instead of IllegalArgumentException.</action>
43+
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.cli.OptionBuilder.create() should throw IllegalStateException instead of IllegalArgumentException.</action>
4344
<!-- ADD -->
4445
<action type="add" issue="CLI-339" dev="ggregory" due-to="Claude Warren, Gary Gregory">Help formatter extension in the new package #314.</action>
4546
<action type="add" dev="ggregory" due-to="Gary Gregory">CommandLine.Builder implements Supplier&lt;CommandLine&gt;.</action>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public final class OptionBuilder {
7272
public static Option create() throws IllegalArgumentException {
7373
if (longOption == null) {
7474
reset();
75-
throw new IllegalArgumentException("must specify longopt");
75+
throw new IllegalStateException("must specify longopt");
7676
}
7777

7878
return create(null);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void testBaseOptionStringOpt() {
5050
void testBuilderIsResettedAlways() {
5151
assertThrows(IllegalArgumentException.class, () -> OptionBuilder.withDescription("JUnit").create('"'));
5252
assertNull(OptionBuilder.create('x').getDescription(), "we inherited a description");
53-
assertThrows(IllegalArgumentException.class, (Executable) OptionBuilder::create);
53+
assertThrows(IllegalStateException.class, (Executable) OptionBuilder::create);
5454
assertNull(OptionBuilder.create('x').getDescription(), "we inherited a description");
5555
}
5656

@@ -77,7 +77,7 @@ void testCompleteOption() {
7777

7878
@Test
7979
void testCreateIncompleteOption() {
80-
assertThrows(IllegalArgumentException.class, (Executable) OptionBuilder::create);
80+
assertThrows(IllegalStateException.class, (Executable) OptionBuilder::create);
8181
// implicitly reset the builder
8282
OptionBuilder.create("opt");
8383
}

0 commit comments

Comments
 (0)