File tree Expand file tree Collapse file tree
main/java/org/apache/commons/cli
test/java/org/apache/commons/cli/bug Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4949 <action dev =" ggregory" type =" fix" due-to =" Alexander Veit, Gary Gregory" issue =" CLI-318" >
5050 Inconsistent date format in changes report.
5151 </action >
52+ <action dev =" ggregory" type =" fix" due-to =" Dilraj Singh, Gary Gregory" issue =" CLI-283" >
53+ Fix NPE in CommandLine.resolveOption(String).
54+ </action >
5255 <!-- ADD -->
5356 <action type =" update" dev =" ggregory" due-to =" Dependabot, Gary Gregory" >
5457 Add github/codeql-action.
Original file line number Diff line number Diff line change @@ -439,16 +439,17 @@ public Iterator<Option> iterator() {
439439 /**
440440 * Retrieves the option object given the long or short option as a String
441441 *
442- * @param opt short or long name of the option.
442+ * @param opt short or long name of the option, may be null .
443443 * @return Canonicalized option.
444444 */
445- private Option resolveOption (String opt ) {
446- opt = Util .stripLeadingHyphens (opt );
447- for (final Option option : options ) {
448- if (opt .equals (option .getOpt ()) || opt .equals (option .getLongOpt ())) {
449- return option ;
445+ private Option resolveOption (final String opt ) {
446+ final String actual = Util .stripLeadingHyphens (opt );
447+ if (actual != null ) {
448+ for (final Option option : options ) {
449+ if (actual .equals (option .getOpt ()) || actual .equals (option .getLongOpt ())) {
450+ return option ;
451+ }
450452 }
451-
452453 }
453454 return null ;
454455 }
Original file line number Diff line number Diff line change 2020import static org .junit .Assert .assertEquals ;
2121import static org .junit .Assert .assertFalse ;
2222import static org .junit .Assert .assertNotNull ;
23+ import static org .junit .Assert .assertNull ;
2324import static org .junit .Assert .assertTrue ;
2425import static org .junit .Assert .fail ;
2526
@@ -135,6 +136,9 @@ public void test11680() throws Exception {
135136
136137 cmd .getOptionValue ("f" , "default f" );
137138 cmd .getOptionValue ("m" , "default m" );
139+ //
140+ assertNull (cmd .getOptionValue ((String ) null , null ));
141+ assertEquals ("default" , cmd .getOptionValue ((String ) null , "default" ));
138142 }
139143
140144 @ Test
You can’t perform that action at this time.
0 commit comments