Skip to content

Commit b0024d4

Browse files
deepygarydgregory
authored andcommitted
[CLI-282] TypeHandler should throw ParseException for an unsupported
class.
1 parent e400f92 commit b0024d4

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
<action type="add" dev="ggregory" due-to="Jason Dillon" issue="CLI-276">
3939
Adjust access-modifier of checkRequiredOptions() to protected.
4040
</action>
41+
<action type="add" dev="ggregory" due-to="Alex Nordlund" issue="CLI-282">
42+
TypeHandler should throw ParseException for an unsupported class.
43+
</action>
4144
</release>
4245

4346
<release version="1.4" date="2017-03-09" description="New features and bug fixes">

src/main/java/org/apache/commons/cli/TypeHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ else if (PatternOptionBuilder.URL_VALUE == clazz)
100100
}
101101
else
102102
{
103-
return null;
103+
throw new ParseException("Unable to handle the class: " + clazz);
104104
}
105105
}
106106

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ public void testCreateValueURL_malformed()
148148
TypeHandler.createValue("malformed-url", PatternOptionBuilder.URL_VALUE);
149149
}
150150

151+
@Test(expected = ParseException.class)
152+
public void testCreateValueInteger_failure()
153+
throws Exception
154+
{
155+
TypeHandler.createValue("just-a-string", Integer.class);
156+
}
157+
151158
public static class Instantiable
152159
{
153160
}

0 commit comments

Comments
 (0)