Browse Source

Polishing

pull/622/head
Juergen Hoeller 12 years ago
parent
commit
a31ebb6c1e
  1. 5
      spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
  2. 7
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
  3. 9
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
  4. 36
      spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java
  5. 13
      spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java
  6. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java
  7. 14
      spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java
  8. 48
      spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java
  9. 2
      spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
  10. 10
      spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

5
spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -170,8 +170,7 @@ public interface BeanFactory {
* <p>Allows for specifying explicit constructor arguments / factory method arguments, * <p>Allows for specifying explicit constructor arguments / factory method arguments,
* overriding the specified default arguments (if any) in the bean definition. * overriding the specified default arguments (if any) in the bean definition.
* @param name the name of the bean to retrieve * @param name the name of the bean to retrieve
* @param args arguments to use if creating a prototype using explicit arguments to a * @param args arguments to use if creating a prototype using explicit arguments
* static factory method. It is invalid to use a non-null args value in any other case.
* @return an instance of the bean * @return an instance of the bean
* @throws NoSuchBeanDefinitionException if there is no such bean definition * @throws NoSuchBeanDefinitionException if there is no such bean definition
* @throws BeanDefinitionStoreException if arguments have been given but * @throws BeanDefinitionStoreException if arguments have been given but

7
spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

@ -239,7 +239,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
AnnotationAttributes annotation = findAutowiredAnnotation(candidate); AnnotationAttributes annotation = findAutowiredAnnotation(candidate);
if (annotation != null) { if (annotation != null) {
if (requiredConstructor != null) { if (requiredConstructor != null) {
throw new BeanCreationException("Invalid autowire-marked constructor: " + candidate + throw new BeanCreationException(beanName,
"Invalid autowire-marked constructor: " + candidate +
". Found another constructor with 'required' Autowired annotation: " + ". Found another constructor with 'required' Autowired annotation: " +
requiredConstructor); requiredConstructor);
} }
@ -250,10 +251,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
boolean required = determineRequiredStatus(annotation); boolean required = determineRequiredStatus(annotation);
if (required) { if (required) {
if (!candidates.isEmpty()) { if (!candidates.isEmpty()) {
throw new BeanCreationException( throw new BeanCreationException(beanName,
"Invalid autowire-marked constructors: " + candidates + "Invalid autowire-marked constructors: " + candidates +
". Found another constructor with 'required' Autowired annotation: " + ". Found another constructor with 'required' Autowired annotation: " +
requiredConstructor); candidate);
} }
requiredConstructor = candidate; requiredConstructor = candidate;
} }

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

@ -285,8 +285,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
if (dependsOn != null) { if (dependsOn != null) {
for (String dependsOnBean : dependsOn) { for (String dependsOnBean : dependsOn) {
if (isDependent(beanName, dependsOnBean)) { if (isDependent(beanName, dependsOnBean)) {
throw new BeanCreationException("Circular depends-on relationship between '" + throw new BeanCreationException(mbd.getResourceDescription(), beanName,
beanName + "' and '" + dependsOnBean + "'"); "Circular depends-on relationship between '" + beanName + "' and '" + dependsOnBean + "'");
} }
registerDependentBean(dependsOnBean, beanName); registerDependentBean(dependsOnBean, beanName);
getBean(dependsOnBean); getBean(dependsOnBean);
@ -1274,7 +1274,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
// Check validity of the usage of the args parameter. This can // Check validity of the usage of the args parameter. This can
// only be used for prototypes constructed via a factory method. // only be used for prototypes constructed via a factory method.
if (args != null && !mbd.isPrototype()) { if (args != null && !mbd.isPrototype()) {
throw new BeanDefinitionStoreException( throw new BeanDefinitionStoreException(mbd.getResourceDescription(), beanName,
"Can only specify arguments for the getBean method when referring to a prototype bean definition"); "Can only specify arguments for the getBean method when referring to a prototype bean definition");
} }
} }
@ -1625,8 +1625,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* instantiation within this class is performed by this method. * instantiation within this class is performed by this method.
* @param beanName the name of the bean * @param beanName the name of the bean
* @param mbd the merged bean definition for the bean * @param mbd the merged bean definition for the bean
* @param args arguments to use if creating a prototype using explicit arguments to a * @param args arguments to use if creating a prototype using explicit arguments
* static factory method. This parameter must be {@code null} except in this case.
* @return a new instance of the bean * @return a new instance of the bean
* @throws BeanCreationException if the bean could not be created * @throws BeanCreationException if the bean could not be created
*/ */

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

@ -25,7 +25,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.cglib.core.SpringNamingPolicy; import org.springframework.cglib.core.SpringNamingPolicy;
import org.springframework.cglib.proxy.Callback; import org.springframework.cglib.proxy.Callback;
import org.springframework.cglib.proxy.CallbackFilter; import org.springframework.cglib.proxy.CallbackFilter;
@ -89,14 +88,13 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
*/ */
private static class CglibSubclassCreator { private static class CglibSubclassCreator {
private static final Class<?>[] CALLBACK_TYPES = new Class<?>[] { NoOp.class, private static final Class<?>[] CALLBACK_TYPES = new Class<?>[]
LookupOverrideMethodInterceptor.class, ReplaceOverrideMethodInterceptor.class }; {NoOp.class, LookupOverrideMethodInterceptor.class, ReplaceOverrideMethodInterceptor.class};
private final RootBeanDefinition beanDefinition; private final RootBeanDefinition beanDefinition;
private final BeanFactory owner; private final BeanFactory owner;
CglibSubclassCreator(RootBeanDefinition beanDefinition, BeanFactory owner) { CglibSubclassCreator(RootBeanDefinition beanDefinition, BeanFactory owner) {
this.beanDefinition = beanDefinition; this.beanDefinition = beanDefinition;
this.owner = owner; this.owner = owner;
@ -113,7 +111,6 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
*/ */
Object instantiate(Constructor<?> ctor, Object[] args) { Object instantiate(Constructor<?> ctor, Object[] args) {
Class<?> subclass = createEnhancedSubclass(this.beanDefinition); Class<?> subclass = createEnhancedSubclass(this.beanDefinition);
Object instance; Object instance;
if (ctor == null) { if (ctor == null) {
instance = BeanUtils.instantiate(subclass); instance = BeanUtils.instantiate(subclass);
@ -123,19 +120,17 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
Constructor<?> enhancedSubclassConstructor = subclass.getConstructor(ctor.getParameterTypes()); Constructor<?> enhancedSubclassConstructor = subclass.getConstructor(ctor.getParameterTypes());
instance = enhancedSubclassConstructor.newInstance(args); instance = enhancedSubclassConstructor.newInstance(args);
} }
catch (Exception e) { catch (Exception ex) {
throw new BeanInstantiationException(this.beanDefinition.getBeanClass(), String.format( throw new BeanInstantiationException(this.beanDefinition.getBeanClass(), String.format(
"Failed to invoke construcor for CGLIB enhanced subclass [%s]", subclass.getName()), e); "Failed to invoke constructor for CGLIB enhanced subclass [%s]", subclass.getName()), ex);
} }
} }
// SPR-10785: set callbacks directly on the instance instead of in the // SPR-10785: set callbacks directly on the instance instead of in the
// enhanced class (via the Enhancer) in order to avoid memory leaks. // enhanced class (via the Enhancer) in order to avoid memory leaks.
Factory factory = (Factory) instance; Factory factory = (Factory) instance;
factory.setCallbacks(new Callback[] { NoOp.INSTANCE,// factory.setCallbacks(new Callback[] {NoOp.INSTANCE,
new LookupOverrideMethodInterceptor(beanDefinition, owner),// new LookupOverrideMethodInterceptor(this.beanDefinition, this.owner),
new ReplaceOverrideMethodInterceptor(beanDefinition, owner) }); new ReplaceOverrideMethodInterceptor(this.beanDefinition, this.owner)});
return instance; return instance;
} }
@ -153,6 +148,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
} }
} }
/** /**
* Class providing hashCode and equals methods required by CGLIB to * Class providing hashCode and equals methods required by CGLIB to
* ensure that CGLIB doesn't generate a distinct class per bean. * ensure that CGLIB doesn't generate a distinct class per bean.
@ -162,7 +158,6 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
private final RootBeanDefinition beanDefinition; private final RootBeanDefinition beanDefinition;
CglibIdentitySupport(RootBeanDefinition beanDefinition) { CglibIdentitySupport(RootBeanDefinition beanDefinition) {
this.beanDefinition = beanDefinition; this.beanDefinition = beanDefinition;
} }
@ -173,8 +168,8 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return other.getClass().equals(this.getClass()) return (getClass().equals(other.getClass()) &&
&& ((CglibIdentitySupport) other).getBeanDefinition().equals(this.getBeanDefinition()); this.beanDefinition.equals(((CglibIdentitySupport) other).beanDefinition));
} }
@Override @Override
@ -183,6 +178,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
} }
} }
/** /**
* CGLIB callback for filtering method interception behavior. * CGLIB callback for filtering method interception behavior.
*/ */
@ -190,7 +186,6 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
private static final Log logger = LogFactory.getLog(MethodOverrideCallbackFilter.class); private static final Log logger = LogFactory.getLog(MethodOverrideCallbackFilter.class);
MethodOverrideCallbackFilter(RootBeanDefinition beanDefinition) { MethodOverrideCallbackFilter(RootBeanDefinition beanDefinition) {
super(beanDefinition); super(beanDefinition);
} }
@ -210,11 +205,12 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
else if (methodOverride instanceof ReplaceOverride) { else if (methodOverride instanceof ReplaceOverride) {
return METHOD_REPLACER; return METHOD_REPLACER;
} }
throw new UnsupportedOperationException("Unexpected MethodOverride subclass: " throw new UnsupportedOperationException("Unexpected MethodOverride subclass: " +
+ methodOverride.getClass().getName()); methodOverride.getClass().getName());
} }
} }
/** /**
* CGLIB MethodInterceptor to override methods, replacing them with an * CGLIB MethodInterceptor to override methods, replacing them with an
* implementation that returns a bean looked up in the container. * implementation that returns a bean looked up in the container.
@ -223,7 +219,6 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
private final BeanFactory owner; private final BeanFactory owner;
LookupOverrideMethodInterceptor(RootBeanDefinition beanDefinition, BeanFactory owner) { LookupOverrideMethodInterceptor(RootBeanDefinition beanDefinition, BeanFactory owner) {
super(beanDefinition); super(beanDefinition);
this.owner = owner; this.owner = owner;
@ -245,7 +240,6 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
private final BeanFactory owner; private final BeanFactory owner;
ReplaceOverrideMethodInterceptor(RootBeanDefinition beanDefinition, BeanFactory owner) { ReplaceOverrideMethodInterceptor(RootBeanDefinition beanDefinition, BeanFactory owner) {
super(beanDefinition); super(beanDefinition);
this.owner = owner; this.owner = owner;
@ -255,7 +249,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable { public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable {
ReplaceOverride ro = (ReplaceOverride) getBeanDefinition().getMethodOverrides().getOverride(method); ReplaceOverride ro = (ReplaceOverride) getBeanDefinition().getMethodOverrides().getOverride(method);
// TODO could cache if a singleton for minor performance optimization // TODO could cache if a singleton for minor performance optimization
MethodReplacer mr = owner.getBean(ro.getMethodReplacerBeanName(), MethodReplacer.class); MethodReplacer mr = this.owner.getBean(ro.getMethodReplacerBeanName(), MethodReplacer.class);
return mr.reimplement(obj, method, args); return mr.reimplement(obj, method, args);
} }
} }

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

@ -37,8 +37,7 @@ public class LookupOverride extends MethodOverride {
/** /**
* Construct a new LookupOverride. * Construct a new LookupOverride.
* @param methodName the name of the method to override. * @param methodName the name of the method to override
* This method must have no arguments.
* @param beanName the name of the bean in the current BeanFactory * @param beanName the name of the bean in the current BeanFactory
* that the overridden method should return * that the overridden method should return
*/ */
@ -48,6 +47,7 @@ public class LookupOverride extends MethodOverride {
this.beanName = beanName; this.beanName = beanName;
} }
/** /**
* Return the name of the bean that should be returned by this method. * Return the name of the bean that should be returned by this method.
*/ */
@ -63,10 +63,6 @@ public class LookupOverride extends MethodOverride {
return (method.getName().equals(getMethodName()) && method.getParameterTypes().length == 0); return (method.getName().equals(getMethodName()) && method.getParameterTypes().length == 0);
} }
@Override
public String toString() {
return "LookupOverride for method '" + getMethodName() + "'; will return bean '" + this.beanName + "'";
}
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
@ -79,4 +75,9 @@ public class LookupOverride extends MethodOverride {
return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.beanName)); return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.beanName));
} }
@Override
public String toString() {
return "LookupOverride for method '" + getMethodName() + "'";
}
} }

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

@ -52,6 +52,7 @@ public abstract class MethodOverride implements BeanMetadataElement {
this.methodName = methodName; this.methodName = methodName;
} }
/** /**
* Return the name of the method to be overridden. * Return the name of the method to be overridden.
*/ */
@ -99,6 +100,7 @@ public abstract class MethodOverride implements BeanMetadataElement {
*/ */
public abstract boolean matches(Method method); public abstract boolean matches(Method method);
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -52,6 +52,7 @@ public class ReplaceOverride extends MethodOverride {
this.methodReplacerBeanName = methodReplacerBeanName; this.methodReplacerBeanName = methodReplacerBeanName;
} }
/** /**
* Return the name of the bean implementing MethodReplacer. * Return the name of the bean implementing MethodReplacer.
*/ */
@ -97,12 +98,6 @@ public class ReplaceOverride extends MethodOverride {
} }
@Override
public String toString() {
return "Replace override for method '" + getMethodName() + "; will call bean '" +
this.methodReplacerBeanName + "'";
}
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (!(other instanceof ReplaceOverride) || !super.equals(other)) { if (!(other instanceof ReplaceOverride) || !super.equals(other)) {
@ -121,4 +116,9 @@ public class ReplaceOverride extends MethodOverride {
return hashCode; return hashCode;
} }
@Override
public String toString() {
return "Replace override for method '" + getMethodName() + "'";
}
} }

48
spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -27,24 +27,26 @@ import java.util.Set;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.tests.sample.beans.factory.DummyFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.MethodReplacer; import org.springframework.beans.factory.support.MethodReplacer;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.tests.sample.beans.factory.DummyFactory;
/** /**
* Types used by {@link XmlBeanFactoryTests} and its attendant XML config files. * Types used by {@link XmlBeanFactoryTests} and its attendant XML config files.
* *
* @author Chris Beams * @author Chris Beams
*/ */
final class XmlBeanFactoryTestTypes { } final class XmlBeanFactoryTestTypes {
}
/** /**
* Simple bean used to check constructor dependency checking. * Simple bean used to check constructor dependency checking.
@ -174,18 +176,12 @@ abstract class ConstructorInjectedOverrides {
return this.tb; return this.tb;
} }
protected abstract FactoryMethods createFactoryMethods(); protected abstract FactoryMethods createFactoryMethods();
/**
* @return Returns the setterString.
*/
public String getSetterString() { public String getSetterString() {
return setterString; return setterString;
} }
/**
* @param setterString The setterString to set.
*/
public void setSetterString(String setterString) { public void setSetterString(String setterString) {
this.setterString = setterString; this.setterString = setterString;
} }
@ -229,7 +225,6 @@ class DerivedConstructorDependenciesBean extends ConstructorDependenciesBean {
private void destroy() { private void destroy() {
this.destroyed = true; this.destroyed = true;
} }
} }
@ -240,7 +235,6 @@ class DerivedConstructorDependenciesBean extends ConstructorDependenciesBean {
interface DummyBo { interface DummyBo {
void something(); void something();
} }
@ -258,9 +252,7 @@ class DummyBoImpl implements DummyBo {
@Override @Override
public void something() { public void something() {
} }
} }
@ -274,7 +266,6 @@ class DummyDao {
public DummyDao(DataSource ds) { public DummyDao(DataSource ds) {
this.ds = ds; this.ds = ds;
} }
} }
@ -290,7 +281,6 @@ class DummyReferencer {
private DummyFactory dummyFactory; private DummyFactory dummyFactory;
public DummyReferencer() { public DummyReferencer() {
} }
@ -321,7 +311,6 @@ class DummyReferencer {
public TestBean getTestBean2() { public TestBean getTestBean2() {
return testBean2; return testBean2;
} }
} }
@ -370,13 +359,11 @@ class FactoryMethods {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
private int num = 0; private int num = 0;
private String name = "default"; private String name = "default";
private TestBean tb; private TestBean tb;
private String stringValue; private String stringValue;
/** /**
* Constructor is private: not for use outside this class, * Constructor is private: not for use outside this class,
* even by IoC container. * even by IoC container.
@ -421,7 +408,6 @@ class FactoryMethods {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }
/** /**
@ -436,7 +422,6 @@ class FixedMethodReplacer implements MethodReplacer {
public Object reimplement(Object obj, Method method, Object[] args) throws Throwable { public Object reimplement(Object obj, Method method, Object[] args) throws Throwable {
return VALUE; return VALUE;
} }
} }
@ -469,22 +454,17 @@ class MethodReplaceCandidate {
public String replaceMe(String echo) { public String replaceMe(String echo) {
return echo; return echo;
} }
} }
/** /**
* Bean that exposes a simple property that can be set * Bean that exposes a simple property that can be set
* to a mix of references and individual values. * to a mix of references and individual values.
*
* @author Rod Johnson
* @since 27.05.2003
*/ */
class MixedCollectionBean { class MixedCollectionBean {
private Collection<?> jumble; private Collection<?> jumble;
public void setJumble(Collection<?> jumble) { public void setJumble(Collection<?> jumble) {
this.jumble = jumble; this.jumble = jumble;
} }
@ -492,7 +472,6 @@ class MixedCollectionBean {
public Collection<?> getJumble() { public Collection<?> getJumble() {
return jumble; return jumble;
} }
} }
@ -504,7 +483,6 @@ interface OverrideInterface {
TestBean getPrototypeDependency(); TestBean getPrototypeDependency();
TestBean getPrototypeDependency(Object someParam); TestBean getPrototypeDependency(Object someParam);
} }
@ -521,7 +499,7 @@ abstract class OverrideOneMethod extends MethodReplaceCandidate implements Overr
return new TestBean(); return new TestBean();
} }
public TestBean invokesOverridenMethodOnSelf() { public TestBean invokesOverriddenMethodOnSelf() {
return getPrototypeDependency(); return getPrototypeDependency();
} }
@ -563,7 +541,6 @@ abstract class OverrideOneMethodSubclass extends OverrideOneMethod {
// This implementation does nothing! // This implementation does nothing!
// It's not overloaded // It's not overloaded
} }
} }
@ -591,7 +568,6 @@ class ProtectedLifecycleBean implements BeanNameAware, BeanFactoryAware, Initial
protected boolean destroyed; protected boolean destroyed;
public void setInitMethodDeclared(boolean initMethodDeclared) { public void setInitMethodDeclared(boolean initMethodDeclared) {
this.initMethodDeclared = initMethodDeclared; this.initMethodDeclared = initMethodDeclared;
} }
@ -707,7 +683,6 @@ class ProtectedLifecycleBean implements BeanNameAware, BeanFactoryAware, Initial
return bean; return bean;
} }
} }
} }
@ -722,7 +697,6 @@ class ReverseMethodReplacer implements MethodReplacer, Serializable {
String s = (String) args[0]; String s = (String) args[0];
return new StringBuffer(s).reverse().toString(); return new StringBuffer(s).reverse().toString();
} }
} }
@ -733,7 +707,6 @@ class ReverseMethodReplacer implements MethodReplacer, Serializable {
abstract class SerializableMethodReplacerCandidate extends MethodReplaceCandidate implements Serializable { abstract class SerializableMethodReplacerCandidate extends MethodReplaceCandidate implements Serializable {
//public abstract Point getPoint(); //public abstract Point getPoint();
} }
@ -769,5 +742,4 @@ class SingleSimpleTypeConstructorBean {
public String getTestString() { public String getTestString() {
return testString; return testString;
} }
} }

2
spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java

@ -1332,7 +1332,7 @@ public final class XmlBeanFactoryTests {
// This differs from Spring's AOP support, which has a distinct notion // This differs from Spring's AOP support, which has a distinct notion
// of a "target" object, meaning that the target needs explicit knowledge // of a "target" object, meaning that the target needs explicit knowledge
// of AOP proxying to invoke an advised method on itself. // of AOP proxying to invoke an advised method on itself.
TestBean jenny3 = oom.invokesOverridenMethodOnSelf(); TestBean jenny3 = oom.invokesOverriddenMethodOnSelf();
assertEquals("Jenny", jenny3.getName()); assertEquals("Jenny", jenny3.getName());
assertNotSame(jenny1, jenny3); assertNotSame(jenny1, jenny3);

10
spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

@ -495,8 +495,7 @@ public abstract class ReflectionUtils {
mc.doWith(method); mc.doWith(method);
} }
catch (IllegalAccessException ex) { catch (IllegalAccessException ex) {
throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName() throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName() + "': " + ex);
+ "': " + ex);
} }
} }
if (clazz.getSuperclass() != null) { if (clazz.getSuperclass() != null) {
@ -607,8 +606,7 @@ public abstract class ReflectionUtils {
fc.doWith(field); fc.doWith(field);
} }
catch (IllegalAccessException ex) { catch (IllegalAccessException ex) {
throw new IllegalStateException( throw new IllegalStateException("Shouldn't be illegal to access field '" + field.getName() + "': " + ex);
"Shouldn't be illegal to access field '" + field.getName() + "': " + ex);
} }
} }
targetClass = targetClass.getSuperclass(); targetClass = targetClass.getSuperclass();
@ -630,8 +628,8 @@ public abstract class ReflectionUtils {
throw new IllegalArgumentException("Destination for field copy cannot be null"); throw new IllegalArgumentException("Destination for field copy cannot be null");
} }
if (!src.getClass().isAssignableFrom(dest.getClass())) { if (!src.getClass().isAssignableFrom(dest.getClass())) {
throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() +
+ "] must be same or subclass as source class [" + src.getClass().getName() + "]"); "] must be same or subclass as source class [" + src.getClass().getName() + "]");
} }
doWithFields(src.getClass(), new FieldCallback() { doWithFields(src.getClass(), new FieldCallback() {
@Override @Override

Loading…
Cancel
Save