Defensively check javaUtilOptionalEmpty

Issue: SPR-11888
This commit is contained in:
Juergen Hoeller
2014-06-19 21:14:43 +02:00
parent cff36d68b1
commit bc1f19ce18

View File

@@ -60,7 +60,8 @@ class TypeConverterDelegate {
try {
Class<?> clazz = ClassUtils.forName("java.util.Optional", TypeConverterDelegate.class.getClassLoader());
javaUtilOptionalEmpty = ClassUtils.getMethod(clazz, "empty").invoke(null);
} catch (Exception ex) {
}
catch (Exception ex) {
// Java 8 not available - conversion to Optional not supported then.
}
}
@@ -257,8 +258,11 @@ class TypeConverterDelegate {
standardConversion = true;
}
}
else if (requiredType.equals(javaUtilOptionalEmpty.getClass())) {
convertedValue = javaUtilOptionalEmpty;
else {
// convertedValue == null
if (javaUtilOptionalEmpty != null && requiredType.equals(javaUtilOptionalEmpty.getClass())) {
convertedValue = javaUtilOptionalEmpty;
}
}
if (!ClassUtils.isAssignableValue(requiredType, convertedValue)) {