Skip to content

Commit 75a8050

Browse files
committed
MethodParameter.equals properly checks overridden containing class
Closes gh-23352
1 parent b5adf8d commit 75a8050

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
@@ -76,6 +76,7 @@ public class MethodParameter {
7676
@Nullable
7777
Map<Integer, Integer> typeIndexesPerLevel;
7878

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

@@ -378,6 +379,12 @@ void setContainingClass(Class<?> containingClass) {
378379
this.containingClass = containingClass;
379380
}
380381

382+
/**
383+
* Return the containing class for this method parameter.
384+
* @return a specific containing class (potentially a subclass of the
385+
* declaring class), or otherwise simply the declaring class itself
386+
* @see #getDeclaringClass()
387+
*/
381388
public Class<?> getContainingClass() {
382389
Class<?> containingClass = this.containingClass;
383390
return (containingClass != null ? containingClass : getDeclaringClass());
@@ -652,7 +659,7 @@ public boolean equals(Object other) {
652659
return false;
653660
}
654661
MethodParameter otherParam = (MethodParameter) other;
655-
return (this.containingClass == otherParam.containingClass &&
662+
return (getContainingClass() == otherParam.getContainingClass() &&
656663
ObjectUtils.nullSafeEquals(this.typeIndexesPerLevel, otherParam.typeIndexesPerLevel) &&
657664
this.nestingLevel == otherParam.nestingLevel &&
658665
this.parameterIndex == otherParam.parameterIndex &&

0 commit comments

Comments
 (0)