@@ -190,6 +190,8 @@ private <T> T convertValue(Object value, Class<?> expectedType) {
190190 || expectedType == Double .class ;
191191
192192 Object flagValue ;
193+ String message = "Flag value had an unexpected type ("
194+ + (value != null ? value .getClass () : "null" ) + "), expected (" + expectedType + ")." ;
193195 if (isPrimitive ) {
194196 if (expectedType == Double .class ) {
195197 if (value instanceof Double ) {
@@ -201,8 +203,19 @@ private <T> T convertValue(Object value, Class<?> expectedType) {
201203 throw new TypeMismatchError ("Flag value string could not be parsed as Double: " + value );
202204 }
203205 } else {
204- throw new TypeMismatchError ("Flag value had an unexpected type "
205- + (value != null ? value .getClass () : "null" ) + ", expected " + expectedType + "." );
206+ throw new TypeMismatchError (message );
207+ }
208+ } else if (expectedType == Integer .class ) {
209+ if (value instanceof Integer ) {
210+ flagValue = value ;
211+ } else if (value instanceof String ) {
212+ try {
213+ flagValue = Integer .parseInt ((String ) value );
214+ } catch (NumberFormatException e ) {
215+ throw new TypeMismatchError ("Flag value string could not be parsed as Integer: " + value );
216+ }
217+ } else {
218+ throw new TypeMismatchError (message );
206219 }
207220 } else {
208221 flagValue = value ;
@@ -212,8 +225,7 @@ private <T> T convertValue(Object value, Class<?> expectedType) {
212225 }
213226
214227 if (!expectedType .isInstance (flagValue )) {
215- throw new TypeMismatchError ("Flag value had an unexpected type "
216- + (flagValue != null ? flagValue .getClass () : "null" + ", expected " + expectedType + "." ));
228+ throw new TypeMismatchError (message );
217229 }
218230 return (T ) flagValue ;
219231 }
0 commit comments