Browse Source

DisposableBeanAdapter ignores bridge method conflicts

Issue: SPR-13922
(cherry picked from commit 903ae48)
pull/966/head
Juergen Hoeller 10 years ago
parent
commit
c960d9733d
  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 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -278,8 +278,12 @@ public abstract class BeanUtils { @@ -278,8 +278,12 @@ public abstract class BeanUtils {
targetMethod = method;
numMethodsFoundWithCurrentMinimumArgs = 1;
}
else {
if (targetMethod.getParameterTypes().length == numParams) {
else if (!method.isBridge() && targetMethod.getParameterTypes().length == numParams) {
if (targetMethod.isBridge()) {
// Prefer regular method over bridge...
targetMethod = method;
}
else {
// Additional candidate with same length
numMethodsFoundWithCurrentMinimumArgs++;
}
@ -289,7 +293,7 @@ public abstract class BeanUtils { @@ -289,7 +293,7 @@ public abstract class BeanUtils {
if (numMethodsFoundWithCurrentMinimumArgs > 1) {
throw new IllegalArgumentException("Cannot resolve method '" + methodName +
"' 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.");
}
return targetMethod;

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -300,7 +300,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { @@ -300,7 +300,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
}
}
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());
}
}

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -2890,7 +2890,13 @@ public class DefaultListableBeanFactoryTests { @@ -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;
@ -2900,8 +2906,10 @@ public class DefaultListableBeanFactoryTests { @@ -2900,8 +2906,10 @@ public class DefaultListableBeanFactoryTests {
this.inner = inner;
}
public void close() {
@Override
public BeanWithDestroyMethod close() {
closeCount++;
return this;
}
}

Loading…
Cancel
Save