Skip to content

UnionMethodMatcher and ClassFilterAwareUnionMethodMatcher have broken eqauls. [SPR-10604] #15233

@spring-projects-issues

Description

@spring-projects-issues

Ivan Sopov opened SPR-10604 and commented

I was investigating the "instanceof vs getClass()== in equals method" problem across the spring framework code-base. It seems that any custom implementation of AbstractResource relying on its equals will lead to inconsistency with all the standard Spring implementations. But I have found a pair of classes with broken equals contract in the spring-aop library:

import org.springframework.aop.MethodMatcher;
import org.springframework.aop.support.ComposablePointcut;
import org.springframework.aop.support.MethodMatchers;

public class MethodMatchersEqualsTest
{
public static void main(String[] args)
{
MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE);
MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(
new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher();

    System.out.println(first.equals(second));
    System.out.println(second.equals(first));
}

}

This code will output:
true
false
So the equals contract is broken for this pair of MethodMatchers.


Affects: 3.2.3

Referenced from: commits f329140, e30b842

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions