Skip to content

Spring fails to find bean's destroy method in case there is a bridge method [SPR-13922] #18494

@spring-projects-issues

Description

@spring-projects-issues

Eduard Valiauka opened SPR-13922 and commented

I have the following classes (in a 3rd-party library):

public abstract class MyAbstractClass {
    public abstract MyAbstractClass shutdown();
}


public class MyImplementation extends MyAbstractClass {
    
    @Override
    public MyImplementation shutdown() {
        //doing smth here
    }
}

When I define a MyImplementation bean, I want to use shutdown as a destroyMethod and get the following exception:

Caused by: org.springframework.beans.factory.support.BeanDefinitionValidationException: Couldn't find a unique destroy method on bean with name 'someName: Cannot resolve method 'shutdown' to a unique method. Attempted to resolve to overloaded method with the least number of parameters, but there were 2 candidates.
	at org.springframework.beans.factory.support.DisposableBeanAdapter.determineDestroyMethod(DisposableBeanAdapter.java:304) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
	at org.springframework.beans.factory.support.DisposableBeanAdapter.<init>(DisposableBeanAdapter.java:123) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.registerDisposableBeanIfNecessary(AbstractBeanFactory.java:1635) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:586) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
	... 42 common frames omitted

The thing is that in fact MyImplementation.class.getMethods() contains 2 shutdown methods. One of them is a real one, another is just a bridge method and can be easily filtered out.
In any case this error message looks very strange.


Affects: 4.2.4

Issue Links:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions