Browse Source

DisposableBeanAdapter ignores bridge method conflicts

Issue: SPR-13922
pull/958/merge
Juergen Hoeller 10 years ago
parent
commit
903ae48382
  1. 12
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
  2. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
  3. 14
      spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java

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

@ -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;

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

@ -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());
} }
} }

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

@ -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;
} }
} }

Loading…
Cancel
Save