File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
spring-core/src/main/java/org/springframework/core/convert/support Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 59
59
*/
60
60
public class GenericConversionService implements ConfigurableConversionService {
61
61
62
- /** Java 8's java.util.Optional.empty() */
63
- private static Object javaUtilOptionalEmpty = null ;
64
-
65
62
/**
66
63
* General NO-OP converter used when conversion is not required.
67
64
*/
@@ -73,11 +70,16 @@ public class GenericConversionService implements ConfigurableConversionService {
73
70
*/
74
71
private static final GenericConverter NO_MATCH = new NoOpConverter ("NO_MATCH" );
75
72
73
+
74
+ /** Java 8's java.util.Optional.empty() */
75
+ private static Object javaUtilOptionalEmpty = null ;
76
+
76
77
static {
77
78
try {
78
79
Class <?> clazz = ClassUtils .forName ("java.util.Optional" , GenericConversionService .class .getClassLoader ());
79
80
javaUtilOptionalEmpty = ClassUtils .getMethod (clazz , "empty" ).invoke (null );
80
- } catch (Exception ex ) {
81
+ }
82
+ catch (Exception ex ) {
81
83
// Java 8 not available - conversion to Optional not supported then.
82
84
}
83
85
}
@@ -225,7 +227,7 @@ public String toString() {
225
227
* @return the converted null object
226
228
*/
227
229
protected Object convertNullSource (TypeDescriptor sourceType , TypeDescriptor targetType ) {
228
- if (targetType .getObjectType ().equals (javaUtilOptionalEmpty .getClass ())) {
230
+ if (javaUtilOptionalEmpty != null && targetType .getObjectType ().equals (javaUtilOptionalEmpty .getClass ())) {
229
231
return javaUtilOptionalEmpty ;
230
232
}
231
233
return null ;
You can’t perform that action at this time.
0 commit comments