DisposableBeanAdapter ignores bridge method conflicts

Issue: SPR-13922
This commit is contained in:
Juergen Hoeller
2016-02-08 13:20:48 +01:00
parent 449f704650
commit 903ae48382
3 changed files with 21 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -278,8 +278,12 @@ public abstract class BeanUtils {
targetMethod = method; targetMethod = method;
numMethodsFoundWithCurrentMinimumArgs = 1; numMethodsFoundWithCurrentMinimumArgs = 1;
} }
else { else if (!method.isBridge() && targetMethod.getParameterTypes().length == numParams) {
if (targetMethod.getParameterTypes().length == numParams) { if (targetMethod.isBridge()) {
// Prefer regular method over bridge...
targetMethod = method;
}
else {
// Additional candidate with same length // Additional candidate with same length
numMethodsFoundWithCurrentMinimumArgs++; numMethodsFoundWithCurrentMinimumArgs++;
} }
@@ -289,7 +293,7 @@ public abstract class BeanUtils {
if (numMethodsFoundWithCurrentMinimumArgs > 1) { if (numMethodsFoundWithCurrentMinimumArgs > 1) {
throw new IllegalArgumentException("Cannot resolve method '" + methodName + throw new IllegalArgumentException("Cannot resolve method '" + methodName +
"' to a unique method. Attempted to resolve to overloaded method with " + "' to a unique method. Attempted to resolve to overloaded method with " +
"the least number of parameters, but there were " + "the least number of parameters but there were " +
numMethodsFoundWithCurrentMinimumArgs + " candidates."); numMethodsFoundWithCurrentMinimumArgs + " candidates.");
} }
return targetMethod; return targetMethod;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -310,7 +310,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
} }
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ex) {
throw new BeanDefinitionValidationException("Couldn't find a unique destroy method on bean with name '" + throw new BeanDefinitionValidationException("Could not find unique destroy method on bean with name '" +
this.beanName + ": " + ex.getMessage()); this.beanName + ": " + ex.getMessage());
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -2890,7 +2890,13 @@ public class DefaultListableBeanFactoryTests {
} }
public static class BeanWithDestroyMethod { public static abstract class BaseClassWithDestroyMethod {
public abstract BaseClassWithDestroyMethod close();
}
public static class BeanWithDestroyMethod extends BaseClassWithDestroyMethod {
private static int closeCount = 0; private static int closeCount = 0;
@@ -2900,8 +2906,10 @@ public class DefaultListableBeanFactoryTests {
this.inner = inner; this.inner = inner;
} }
public void close() { @Override
public BeanWithDestroyMethod close() {
closeCount++; closeCount++;
return this;
} }
} }