File tree Expand file tree Collapse file tree
java/org/apache/commons/cli
test/org/apache/commons/cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616 */
1717package org .apache .commons .cli ;
1818
19+ import java .util .ArrayList ;
1920import java .util .Arrays ;
2021import java .util .Enumeration ;
2122import java .util .Iterator ;
@@ -43,7 +44,7 @@ public abstract class Parser implements CommandLineParser {
4344
4445 protected void setOptions (final Options options ) {
4546 this .options = options ;
46- this .requiredOptions = options .getRequiredOptions ();
47+ this .requiredOptions = new ArrayList ( options .getRequiredOptions () );
4748 }
4849
4950 protected Options getOptions () {
Original file line number Diff line number Diff line change @@ -140,4 +140,26 @@ public void testMissingRequiredOptions()
140140 }
141141 }
142142
143+ public void testReuseOptionsTwice () throws Exception
144+ {
145+ Options opts = new Options ();
146+ opts .addOption (OptionBuilder .isRequired ().create ('v' ));
147+
148+ GnuParser parser = new GnuParser ();
149+
150+ // first parsing
151+ parser .parse (opts , new String [] { "-v" });
152+
153+ try
154+ {
155+ // second parsing, with the same Options instance and an invalid command line
156+ parser .parse (opts , new String [0 ]);
157+ fail ("MissingOptionException not thrown" );
158+ }
159+ catch (MissingOptionException e )
160+ {
161+ // expected
162+ }
163+ }
164+
143165}
You can’t perform that action at this time.
0 commit comments