Skip to content

Commit 903ae48

Browse files
committed
DisposableBeanAdapter ignores bridge method conflicts
Issue: SPR-13922
1 parent 449f704 commit 903ae48

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -278,8 +278,12 @@ public static Method findMethodWithMinimalParameters(Method[] methods, String me
278278
targetMethod = method;
279279
numMethodsFoundWithCurrentMinimumArgs = 1;
280280
}
281-
else {
282-
if (targetMethod.getParameterTypes().length == numParams) {
281+
else if (!method.isBridge() && targetMethod.getParameterTypes().length == numParams) {
282+
if (targetMethod.isBridge()) {
283+
// Prefer regular method over bridge...
284+
targetMethod = method;
285+
}
286+
else {
283287
// Additional candidate with same length
284288
numMethodsFoundWithCurrentMinimumArgs++;
285289
}
@@ -289,7 +293,7 @@ public static Method findMethodWithMinimalParameters(Method[] methods, String me
289293
if (numMethodsFoundWithCurrentMinimumArgs > 1) {
290294
throw new IllegalArgumentException("Cannot resolve method '" + methodName +
291295
"' to a unique method. Attempted to resolve to overloaded method with " +
292-
"the least number of parameters, but there were " +
296+
"the least number of parameters but there were " +
293297
numMethodsFoundWithCurrentMinimumArgs + " candidates.");
294298
}
295299
return targetMethod;

spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -310,7 +310,7 @@ public Method run() {
310310
}
311311
}
312312
catch (IllegalArgumentException ex) {
313-
throw new BeanDefinitionValidationException("Couldn't find a unique destroy method on bean with name '" +
313+
throw new BeanDefinitionValidationException("Could not find unique destroy method on bean with name '" +
314314
this.beanName + ": " + ex.getMessage());
315315
}
316316
}

spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -2890,7 +2890,13 @@ public void close() {
28902890
}
28912891

28922892

2893-
public static class BeanWithDestroyMethod {
2893+
public static abstract class BaseClassWithDestroyMethod {
2894+
2895+
public abstract BaseClassWithDestroyMethod close();
2896+
}
2897+
2898+
2899+
public static class BeanWithDestroyMethod extends BaseClassWithDestroyMethod {
28942900

28952901
private static int closeCount = 0;
28962902

@@ -2900,8 +2906,10 @@ public void setInner(BeanWithDestroyMethod inner) {
29002906
this.inner = inner;
29012907
}
29022908

2903-
public void close() {
2909+
@Override
2910+
public BeanWithDestroyMethod close() {
29042911
closeCount++;
2912+
return this;
29052913
}
29062914
}
29072915

0 commit comments

Comments
 (0)