Skip to content

Commit aebc485

Browse files
committed
MethodParameter.equals properly checks overridden containing class
Closes gh-23352
1 parent ea4f7d3 commit aebc485

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

@@ -383,6 +384,12 @@ void setContainingClass(Class<?> containingClass) {
383384
this.containingClass = containingClass;
384385
}
385386

387+
/**
388+
* Return the containing class for this method parameter.
389+
* @return a specific containing class (potentially a subclass of the
390+
* declaring class), or otherwise simply the declaring class itself
391+
* @see #getDeclaringClass()
392+
*/
386393
public Class<?> getContainingClass() {
387394
Class<?> containingClass = this.containingClass;
388395
return (containingClass != null ? containingClass : getDeclaringClass());
@@ -660,7 +667,7 @@ public boolean equals(Object other) {
660667
return false;
661668
}
662669
MethodParameter otherParam = (MethodParameter) other;
663-
return (this.containingClass == otherParam.containingClass &&
670+
return (getContainingClass() == otherParam.getContainingClass() &&
664671
ObjectUtils.nullSafeEquals(this.typeIndexesPerLevel, otherParam.typeIndexesPerLevel) &&
665672
this.nestingLevel == otherParam.nestingLevel &&
666673
this.parameterIndex == otherParam.parameterIndex &&

0 commit comments

Comments
 (0)