Skip to content

Commit 9774480

Browse files
committed
Applying the patch from CLI-135 to put the public addValue method back, even though it just throws an exception. This maintains binary compatibility, for some level of compatibility.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/branches/cli-1.0.x@551815 13f79535-47bb-0310-9956-ffa450edef68
1 parent 08cf0f5 commit 9774480

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public int getArgs()
401401
*
402402
* @param value is a/the value of this Option
403403
*/
404-
void addValue(String value)
404+
void addValueForProcessing(String value)
405405
{
406406
switch (numberOfArgs)
407407
{
@@ -649,4 +649,11 @@ void clearValues() {
649649
this.values.clear();
650650
}
651651

652+
public boolean addValue(Object object) {
653+
throw new UnsupportedOperationException(
654+
"The addValue method is not intended for client use. " +
655+
"Subclasses should use the addValueForProcessing method instead. "
656+
);
657+
}
658+
652659
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private void processProperties(Properties properties)
258258
{
259259
try
260260
{
261-
opt.addValue(value);
261+
opt.addValueForProcessing(value);
262262
}
263263
catch (RuntimeException exp)
264264
{
@@ -340,7 +340,7 @@ public void processArgs(Option opt, ListIterator iter)
340340
// found a value
341341
try
342342
{
343-
opt.addValue( Util.stripLeadingAndTrailingQuotes(str) );
343+
opt.addValueForProcessing( Util.stripLeadingAndTrailingQuotes(str) );
344344
}
345345
catch (RuntimeException exp)
346346
{

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@
2323
*/
2424
public class OptionTest extends TestCase {
2525

26+
private static class TestOption extends Option {
27+
public TestOption(String opt, boolean hasArg, String description) throws IllegalArgumentException {
28+
super(opt, hasArg, description);
29+
}
30+
public boolean addValue(String value) {
31+
addValueForProcessing(value);
32+
return true;
33+
}
34+
}
35+
2636
public void testClear() {
27-
Option option = new Option("x", true, "");
37+
TestOption option = new TestOption("x", true, "");
2838
assertEquals(0, option.getValuesList().size());
2939
option.addValue("a");
3040
assertEquals(1, option.getValuesList().size());
@@ -34,8 +44,8 @@ public void testClear() {
3444

3545
// See http://issues.apache.org/jira/browse/CLI-21
3646
public void testClone() throws CloneNotSupportedException {
37-
Option a = new Option("a", true, "");
38-
Option b = (Option) a.clone();
47+
TestOption a = new TestOption("a", true, "");
48+
TestOption b = (TestOption) a.clone();
3949
assertEquals(a, b);
4050
assertNotSame(a, b);
4151
a.setDescription("a");

0 commit comments

Comments
 (0)