Skip to content
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

InitDestroyAnnotationBeanPostProcessor @PostConstruct method may not get called [SPR-5945] #10614

Closed
spring-projects-issues opened this issue Jul 20, 2009 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Magnus Jungsbluth opened SPR-5945 and commented

org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor :

if two classes (class A extends class B) both have a method called "afterPropertiesSet()" annotated with @PostConstruct, only the most concrete method gets called. This bug only occurs if the methods have an identical name.

To fix this behaviour, change LifecycleElement's hashCode() method to include the declaring class

public int hashCode() {
return (this.method.getDeclaringClass().getName() + "." + this.method.getName()).hashCode();
}

Change equals() accordingly.


Affects: 2.5.6

Referenced from: commits 4deef37

@spring-projects-issues
Copy link
Collaborator Author

Magnus Jungsbluth commented

Of course, the bug does not depend on the specific name of the annotated method. If two annotated methods are called foo() the same bug occurs.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Thanks for pointing this out! In an effort to not call overridden public/protected methods in a hierarchy twice, we accidentally prevented invocation of multiple private methods of the same name... This is fixed for 3.0 RC1 now.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Magnus Jungsbluth commented

Thanks for fixing this so quickly!

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) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants