@@ -221,9 +221,8 @@ public Class<?> getRawClass() {
221
221
/**
222
222
* Return the underlying source of the resolvable type. Will return a {@link Field},
223
223
* {@link MethodParameter} or {@link Type} depending on how the {@link ResolvableType}
224
- * was constructed. With the exception of the {@link #NONE} constant, this method will
225
- * never return {@code null}. This method is primarily to provide access to additional
226
- * type information or meta-data that alternative JVM languages may provide.
224
+ * was constructed. This method is primarily to provide access to additional type
225
+ * information or meta-data that alternative JVM languages may provide.
227
226
*/
228
227
public Object getSource () {
229
228
Object source = (this .typeProvider != null ? this .typeProvider .getSource () : null );
@@ -1103,20 +1102,20 @@ public static ResolvableType forClassWithGenerics(Class<?> clazz, ResolvableType
1103
1102
* convey generic information but if it implements {@link ResolvableTypeProvider} a
1104
1103
* more precise {@link ResolvableType} can be used than the simple one based on
1105
1104
* the {@link #forClass(Class) Class instance}.
1106
- * @param instance the instance
1107
- * @return a {@link ResolvableType} for the specified instance
1105
+ * @param instance the instance (possibly {@code null})
1106
+ * @return a {@link ResolvableType} for the specified instance,
1107
+ * or {@code NONE} for {@code null}
1108
1108
* @since 4.2
1109
1109
* @see ResolvableTypeProvider
1110
1110
*/
1111
- public static ResolvableType forInstance (Object instance ) {
1112
- Assert .notNull (instance , "Instance must not be null" );
1111
+ public static ResolvableType forInstance (@ Nullable Object instance ) {
1113
1112
if (instance instanceof ResolvableTypeProvider ) {
1114
1113
ResolvableType type = ((ResolvableTypeProvider ) instance ).getResolvableType ();
1115
1114
if (type != null ) {
1116
1115
return type ;
1117
1116
}
1118
1117
}
1119
- return ResolvableType . forClass (instance .getClass ());
1118
+ return ( instance != null ? forClass (instance .getClass ()) : NONE );
1120
1119
}
1121
1120
1122
1121
/**
0 commit comments