Skip to content

Commit 87152d7

Browse files
committed
MethodParameter.equals properly checks overridden containing class
Closes gh-23352
1 parent 5b91297 commit 87152d7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

spring-core/src/main/java/org/springframework/core/MethodParameter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class MethodParameter {
7777
/** Map from Integer level to Integer type index */
7878
Map<Integer, Integer> typeIndexesPerLevel;
7979

80+
/** The containing class. Could also be supplied by overriding {@link #getContainingClass()} */
8081
private volatile Class<?> containingClass;
8182

8283
private volatile Class<?> parameterType;
@@ -345,6 +346,12 @@ void setContainingClass(Class<?> containingClass) {
345346
this.containingClass = containingClass;
346347
}
347348

349+
/**
350+
* Return the containing class for this method parameter.
351+
* @return a specific containing class (potentially a subclass of the
352+
* declaring class), or otherwise simply the declaring class itself
353+
* @see #getDeclaringClass()
354+
*/
348355
public Class<?> getContainingClass() {
349356
return (this.containingClass != null ? this.containingClass : getDeclaringClass());
350357
}
@@ -613,7 +620,7 @@ public boolean equals(Object other) {
613620
return false;
614621
}
615622
MethodParameter otherParam = (MethodParameter) other;
616-
return (this.containingClass == otherParam.containingClass &&
623+
return (getContainingClass() == otherParam.getContainingClass() &&
617624
ObjectUtils.nullSafeEquals(this.typeIndexesPerLevel, otherParam.typeIndexesPerLevel) &&
618625
this.nestingLevel == otherParam.nestingLevel &&
619626
this.parameterIndex == otherParam.parameterIndex &&

0 commit comments

Comments
 (0)