Remove redundant Assert.notNull() checks in ResolvableType

Since equivalent Assert.notNull() checks are already performed by
subsequent code (constructors and factory methods), there is no need
to perform the exact same assertion twice in such use cases.

Closes gh-36544
This commit is contained in:
Sam Brannen
2026-03-26 15:46:02 +01:00
parent ccf0cae18c
commit 5e975f51dd
2 changed files with 28 additions and 7 deletions
@@ -1152,7 +1152,6 @@ public class ResolvableType implements Serializable {
* @see #forClassWithGenerics(Class, ResolvableType...)
*/
public static ResolvableType forClassWithGenerics(Class<?> clazz, Class<?>... generics) {
Assert.notNull(clazz, "Class must not be null");
Assert.notNull(generics, "Generics array must not be null");
ResolvableType[] resolvableGenerics = new ResolvableType[generics.length];
for (int i = 0; i < generics.length; i++) {
@@ -1289,7 +1288,6 @@ public class ResolvableType implements Serializable {
* @see #forConstructorParameter(Constructor, int, Class)
*/
public static ResolvableType forConstructorParameter(Constructor<?> constructor, int parameterIndex) {
Assert.notNull(constructor, "Constructor must not be null");
return forMethodParameter(new MethodParameter(constructor, parameterIndex));
}
@@ -1307,7 +1305,6 @@ public class ResolvableType implements Serializable {
public static ResolvableType forConstructorParameter(Constructor<?> constructor, int parameterIndex,
Class<?> implementationClass) {
Assert.notNull(constructor, "Constructor must not be null");
MethodParameter methodParameter = new MethodParameter(constructor, parameterIndex, implementationClass);
return forMethodParameter(methodParameter);
}
@@ -1319,7 +1316,6 @@ public class ResolvableType implements Serializable {
* @see #forMethodReturnType(Method, Class)
*/
public static ResolvableType forMethodReturnType(Method method) {
Assert.notNull(method, "Method must not be null");
return forMethodParameter(new MethodParameter(method, -1));
}
@@ -1333,7 +1329,6 @@ public class ResolvableType implements Serializable {
* @see #forMethodReturnType(Method)
*/
public static ResolvableType forMethodReturnType(Method method, Class<?> implementationClass) {
Assert.notNull(method, "Method must not be null");
MethodParameter methodParameter = new MethodParameter(method, -1, implementationClass);
return forMethodParameter(methodParameter);
}
@@ -1347,7 +1342,6 @@ public class ResolvableType implements Serializable {
* @see #forMethodParameter(MethodParameter)
*/
public static ResolvableType forMethodParameter(Method method, int parameterIndex) {
Assert.notNull(method, "Method must not be null");
return forMethodParameter(new MethodParameter(method, parameterIndex));
}
@@ -1363,7 +1357,6 @@ public class ResolvableType implements Serializable {
* @see #forMethodParameter(MethodParameter)
*/
public static ResolvableType forMethodParameter(Method method, int parameterIndex, Class<?> implementationClass) {
Assert.notNull(method, "Method must not be null");
MethodParameter methodParameter = new MethodParameter(method, parameterIndex, implementationClass);
return forMethodParameter(methodParameter);
}
@@ -221,6 +221,13 @@ class ResolvableTypeTests {
.withMessage("Constructor must not be null");
}
@Test
void forConstructorParameterWithImplementationClassMustNotBeNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forConstructorParameter(null, 0, TypedConstructors.class))
.withMessage("Executable must not be null");
}
@Test
void forMethodParameterByIndex() throws Exception {
Method method = Methods.class.getMethod("charSequenceParameter", List.class);
@@ -235,6 +242,13 @@ class ResolvableTypeTests {
.withMessage("Method must not be null");
}
@Test
void forMethodParameterByIndexWithImplementationClassMustNotBeNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forMethodParameter(null, 0, TypedMethods.class))
.withMessage("Executable must not be null");
}
@Test
void forMethodParameter() throws Exception {
Method method = Methods.class.getMethod("charSequenceParameter", List.class);
@@ -302,6 +316,13 @@ class ResolvableTypeTests {
.withMessage("Method must not be null");
}
@Test
void forMethodReturnWithImplementationClassMustNotBeNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forMethodReturnType(null, TypedMethods.class))
.withMessage("Executable must not be null");
}
@Test // gh-27748
void genericMatchesReturnType() throws Exception {
Method method = SomeRepository.class.getMethod("someMethod", Class.class, Class.class, Class.class);
@@ -1307,6 +1328,13 @@ class ResolvableTypeTests {
assertThat(type.asMap().toString()).isEqualTo("java.util.Map<java.lang.Integer, java.util.List<java.lang.String>>");
}
@Test
void forClassWithGenericsClassMustNotBeNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forClassWithGenerics(null, String.class))
.withMessage("Class must not be null");
}
@Test
void forClassWithMismatchedGenerics() {
assertThatIllegalArgumentException()