[CLI-282] TypeHandler should throw ParseException for an unsupported
class.
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d42edbb..6cfcc8d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -38,6 +38,9 @@
<action type="add" dev="ggregory" due-to="Jason Dillon" issue="CLI-276">
Adjust access-modifier of checkRequiredOptions() to protected.
</action>
+ <action type="add" dev="ggregory" due-to="Alex Nordlund" issue="CLI-282">
+ TypeHandler should throw ParseException for an unsupported class.
+ </action>
</release>
<release version="1.4" date="2017-03-09" description="New features and bug fixes">
diff --git a/src/main/java/org/apache/commons/cli/TypeHandler.java b/src/main/java/org/apache/commons/cli/TypeHandler.java
index 6bd84b0..9ed8beb 100644
--- a/src/main/java/org/apache/commons/cli/TypeHandler.java
+++ b/src/main/java/org/apache/commons/cli/TypeHandler.java
@@ -100,7 +100,7 @@
}
else
{
- return null;
+ throw new ParseException("Unable to handle the class: " + clazz);
}
}
diff --git a/src/test/java/org/apache/commons/cli/TypeHandlerTest.java b/src/test/java/org/apache/commons/cli/TypeHandlerTest.java
index 1d7f8cf..13e7672 100644
--- a/src/test/java/org/apache/commons/cli/TypeHandlerTest.java
+++ b/src/test/java/org/apache/commons/cli/TypeHandlerTest.java
@@ -148,6 +148,13 @@
TypeHandler.createValue("malformed-url", PatternOptionBuilder.URL_VALUE);
}
+ @Test(expected = ParseException.class)
+ public void testCreateValueInteger_failure()
+ throws Exception
+ {
+ TypeHandler.createValue("just-a-string", Integer.class);
+ }
+
public static class Instantiable
{
}