Skip to content

Inclusion of overloaded in equals() and hashCode() for MethodOverride breaks equals() in AbstractBeanDefinition [SPR-11420] #16047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
spring-projects-issues opened this issue Feb 12, 2014 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 12, 2014

Sam Brannen opened SPR-11420 and commented

Status Quo

The overloaded flag in MethodOverride is a mutable property that is only intended to be used "to optimize runtime performance" (from the Javadoc), specifically limited to the implementation of ReplaceOverride.matches().

The overloaded flag is, however, currently used to determine equality of and calculate hash codes for MethodOverride instances.

Its value is potentially changed from true (the default) to false in AbstractBeanDefinition.validate(). As a consequence, given two bean definitions A and B that represent the exact same bean definition metadata for a bean that relies on method injection (perhaps loaded via separate application contexts in the same VM), if A has been validated and B has not, then A.equals(B) will potentially return false, which is not acceptable behavior.

Note that AbstractBeanDefinition.equals() includes an equality check for MethodOverrides.

Deliverables

  1. Stop including the overloaded flag in equals() and hashCode() for MethodOverride.

Affects: 3.0 GA

Issue Links:

Backported to: 3.2.8

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Fixed as described in the comments for GitHub commits 9534245 (4.0.2) and 9f77ef4 (3.2.8):

Exclude overloaded from equals & hashCode in MethodOverride

Prior to this commit, the inclusion of the 'overloaded' flag in the
implementations of equals() and hashCode() in MethodOverride could lead
to adverse effects in the outcome of equals() in AbstractBeanDefinition.

For example, given two bean definitions A and B that represent the
exact same bean definition metadata for a bean that relies on method
injection, if A has been validated and B has not, then A.equals(B) will
potentially return false, which is not acceptable behavior.

This commit addresses this issue by removing the 'overloaded' flag from
the implementations of equals() and hashCode() for MethodOverride.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 12, 2014

Sam Brannen commented

Changed priority to major since it has been determined that this bug was actually the cause of the memory leak for method injected beans (see #15411).

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.0.2 milestone Jan 11, 2019
@sbrannen sbrannen changed the title Inclusion of 'overloaded' in equals() and hashCode() for MethodOverride breaks equals() in AbstractBeanDefinition [SPR-11420] Inclusion of overloaded in equals() and hashCode() for MethodOverride breaks equals() in AbstractBeanDefinition [SPR-11420] Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants