@@ -221,9 +221,8 @@ public Class<?> getRawClass() {
221221 /**
222222 * Return the underlying source of the resolvable type. Will return a {@link Field},
223223 * {@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.
227226 */
228227 public Object getSource () {
229228 Object source = (this .typeProvider != null ? this .typeProvider .getSource () : null );
@@ -1103,20 +1102,20 @@ public static ResolvableType forClassWithGenerics(Class<?> clazz, ResolvableType
11031102 * convey generic information but if it implements {@link ResolvableTypeProvider} a
11041103 * more precise {@link ResolvableType} can be used than the simple one based on
11051104 * 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}
11081108 * @since 4.2
11091109 * @see ResolvableTypeProvider
11101110 */
1111- public static ResolvableType forInstance (Object instance ) {
1112- Assert .notNull (instance , "Instance must not be null" );
1111+ public static ResolvableType forInstance (@ Nullable Object instance ) {
11131112 if (instance instanceof ResolvableTypeProvider ) {
11141113 ResolvableType type = ((ResolvableTypeProvider ) instance ).getResolvableType ();
11151114 if (type != null ) {
11161115 return type ;
11171116 }
11181117 }
1119- return ResolvableType . forClass (instance .getClass ());
1118+ return ( instance != null ? forClass (instance .getClass ()) : NONE );
11201119 }
11211120
11221121 /**
0 commit comments