Skip to content

Commit 83b7ceb

Browse files
author
John Keyes
committed
bug no. 11680 resolved
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129800 13f79535-47bb-0310-9956-ffa450edef68
1 parent f9df518 commit 83b7ceb

2 files changed

Lines changed: 73 additions & 5 deletions

File tree

src/java/org/apache/commons/cli/CommandLine.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,14 @@ public String getOptionValue( char opt ) {
168168
public String[] getOptionValues( String opt ) {
169169
List values = new java.util.ArrayList();
170170

171-
List opts = (List)options.get( opt );
172-
Iterator iter = opts.iterator();
171+
if( options.containsKey( opt ) ) {
172+
List opts = (List)options.get( opt );
173+
Iterator iter = opts.iterator();
173174

174-
while( iter.hasNext() ) {
175-
Option optt = (Option)iter.next();
176-
values.addAll( optt.getValuesList() );
175+
while( iter.hasNext() ) {
176+
Option optt = (Option)iter.next();
177+
values.addAll( optt.getValuesList() );
178+
}
177179
}
178180
return (values.size() == 0) ? null : (String[])values.toArray(new String[]{});
179181
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) The Apache Software Foundation. All rights reserved.
3+
*
4+
* This software is published under the terms of the Apache Software License
5+
* version 1.1, a copy of which has been included with this distribution in
6+
* the LICENSE file.
7+
*
8+
* $Id: BugsTest.java,v 1.1 2002/08/15 20:31:23 jkeyes Exp $
9+
*/
10+
11+
package org.apache.commons.cli;
12+
13+
import junit.framework.Test;
14+
import junit.framework.TestCase;
15+
import junit.framework.TestSuite;
16+
17+
public class BugsTest extends TestCase
18+
{
19+
/** CommandLine instance */
20+
private CommandLine _cmdline = null;
21+
private Option _option = null;
22+
23+
public static Test suite() {
24+
return new TestSuite( BugsTest.class );
25+
}
26+
27+
public BugsTest( String name )
28+
{
29+
super( name );
30+
}
31+
32+
public void setUp()
33+
{
34+
}
35+
36+
public void tearDown()
37+
{
38+
}
39+
40+
public void test11680()
41+
{
42+
Options options = new Options();
43+
options.addOption("f", true, "foobar");
44+
options.addOption("m", true, "missing");
45+
String[] args = new String[] { "-f" , "foo" };
46+
47+
CommandLineParser parser = CommandLineParserFactory.newParser();
48+
49+
try {
50+
CommandLine cmd = parser.parse( options, args );
51+
52+
try {
53+
cmd.getOptionValue( "f", "default f");
54+
cmd.getOptionValue( "m", "default m");
55+
}
56+
catch( NullPointerException exp ) {
57+
fail( "NullPointer caught: " + exp.getMessage() );
58+
}
59+
}
60+
catch( ParseException exp ) {
61+
fail( "Unexpected Exception: " + exp.getMessage() );
62+
}
63+
64+
65+
}
66+
}

0 commit comments

Comments
 (0)