File tree Expand file tree Collapse file tree
main/java/org/apache/commons/cli
test/java/org/apache/commons/cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5555 <action dev =" ggregory" type =" fix" due-to =" Dilraj Singh, Gary Gregory" issue =" CLI-283" >
5656 CommandLine.addOption(Option) should not allow a null Option.
5757 </action >
58+ <action dev =" ggregory" type =" fix" due-to =" Gary Gregory" issue =" CLI-283" >
59+ CommandLine.addArgs(String) should not allow a null String.
60+ </action >
5861 <!-- ADD -->
5962 <action type =" update" dev =" ggregory" due-to =" Dependabot, Gary Gregory" >
6063 Add github/codeql-action.
Original file line number Diff line number Diff line change @@ -99,7 +99,9 @@ protected CommandLine() {
9999 * @param arg the unrecognized option/argument.
100100 */
101101 protected void addArg (final String arg ) {
102- args .add (arg );
102+ if (arg != null ) {
103+ args .add (arg );
104+ }
103105 }
104106
105107 /**
Original file line number Diff line number Diff line change @@ -41,10 +41,23 @@ public void testBuilder() {
4141 }
4242
4343 @ Test
44- public void testBuilderNulls () {
44+ public void testBuilderNullArgs () {
45+ final CommandLine .Builder builder = new CommandLine .Builder ();
46+ builder .addArg (null ).addArg (null );
47+ builder .addOption (Option .builder ("T" ).build ());
48+ final CommandLine cmd = builder .build ();
49+
50+ assertEquals (0 , cmd .getArgs ().length );
51+ assertEquals ("T" , cmd .getOptions ()[0 ].getOpt ());
52+ }
53+
54+ @ Test
55+ public void testBuilderNullOption () {
4556 final CommandLine .Builder builder = new CommandLine .Builder ();
4657 builder .addArg ("foo" ).addArg ("bar" );
4758 builder .addOption (null );
59+ builder .addOption (null );
60+ builder .addOption (null );
4861 final CommandLine cmd = builder .build ();
4962
5063 assertEquals ("foo" , cmd .getArgs ()[0 ]);
You can’t perform that action at this time.
0 commit comments