Browse Source

Polishing

pull/1359/head
Juergen Hoeller 9 years ago
parent
commit
c2a1a41eb6
  1. 5
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java
  2. 7
      spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java
  3. 5
      spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessorAdapter.java
  4. 9
      spring-beans/src/main/java/org/springframework/beans/factory/config/Scope.java
  5. 47
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
  6. 48
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
  7. 2
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java
  8. 152
      spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java
  9. 2
      spring-core/src/main/java/org/springframework/util/ReflectionUtils.java
  10. 9
      spring-web/src/main/java/org/springframework/http/client/AbstractAsyncClientHttpRequest.java
  11. 30
      spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java
  12. 33
      spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 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.
@ -141,8 +141,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP
@Override @Override
public PropertyValues postProcessPropertyValues( public PropertyValues postProcessPropertyValues(
PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
throws BeansException {
if (!this.validatedBeanNames.contains(beanName)) { if (!this.validatedBeanNames.contains(beanName)) {
if (!shouldSkip(this.beanFactory, beanName)) { if (!shouldSkip(this.beanFactory, beanName)) {

7
spring-beans/src/main/java/org/springframework/beans/factory/config/InstantiationAwareBeanPostProcessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 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.
@ -96,14 +96,13 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor {
* dependency types - which the factory handles specifically - already filtered out) * dependency types - which the factory handles specifically - already filtered out)
* @param bean the bean instance created, but whose properties have not yet been set * @param bean the bean instance created, but whose properties have not yet been set
* @param beanName the name of the bean * @param beanName the name of the bean
* @return the actual property values to apply to to the given bean * @return the actual property values to apply to the given bean
* (can be the passed-in PropertyValues instance), or {@code null} * (can be the passed-in PropertyValues instance), or {@code null}
* to skip property population * to skip property population
* @throws org.springframework.beans.BeansException in case of errors * @throws org.springframework.beans.BeansException in case of errors
* @see org.springframework.beans.MutablePropertyValues * @see org.springframework.beans.MutablePropertyValues
*/ */
PropertyValues postProcessPropertyValues( PropertyValues postProcessPropertyValues(
PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException;
throws BeansException;
} }

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 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.
@ -66,8 +66,7 @@ public abstract class InstantiationAwareBeanPostProcessorAdapter implements Smar
@Override @Override
public PropertyValues postProcessPropertyValues( public PropertyValues postProcessPropertyValues(
PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
throws BeansException {
return pvs; return pvs;
} }

9
spring-beans/src/main/java/org/springframework/beans/factory/config/Scope.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 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.
@ -68,6 +68,7 @@ public interface Scope {
* @param objectFactory the {@link ObjectFactory} to use to create the scoped * @param objectFactory the {@link ObjectFactory} to use to create the scoped
* object if it is not present in the underlying storage mechanism * object if it is not present in the underlying storage mechanism
* @return the desired object (never {@code null}) * @return the desired object (never {@code null})
* @throws IllegalStateException if the underlying scope is not currently active
*/ */
Object get(String name, ObjectFactory<?> objectFactory); Object get(String name, ObjectFactory<?> objectFactory);
@ -84,6 +85,7 @@ public interface Scope {
* removing an object. * removing an object.
* @param name the name of the object to remove * @param name the name of the object to remove
* @return the removed object, or {@code null} if no object was present * @return the removed object, or {@code null} if no object was present
* @throws IllegalStateException if the underlying scope is not currently active
* @see #registerDestructionCallback * @see #registerDestructionCallback
*/ */
Object remove(String name); Object remove(String name);
@ -100,7 +102,7 @@ public interface Scope {
* at the appropriate time. If such a callback is not supported by the * at the appropriate time. If such a callback is not supported by the
* underlying runtime environment at all, the callback <i>must be * underlying runtime environment at all, the callback <i>must be
* ignored and a corresponding warning should be logged</i>. * ignored and a corresponding warning should be logged</i>.
* <p>Note that 'destruction' refers to to automatic destruction of * <p>Note that 'destruction' refers to automatic destruction of
* the object as part of the scope's own lifecycle, not to the individual * the object as part of the scope's own lifecycle, not to the individual
* scoped object having been explicitly removed by the application. * scoped object having been explicitly removed by the application.
* If a scoped object gets removed via this facade's {@link #remove(String)} * If a scoped object gets removed via this facade's {@link #remove(String)}
@ -112,6 +114,7 @@ public interface Scope {
* so it can safely be executed without an enclosing try-catch block. * so it can safely be executed without an enclosing try-catch block.
* Furthermore, the Runnable will usually be serializable, provided * Furthermore, the Runnable will usually be serializable, provided
* that its target object is serializable as well. * that its target object is serializable as well.
* @throws IllegalStateException if the underlying scope is not currently active
* @see org.springframework.beans.factory.DisposableBean * @see org.springframework.beans.factory.DisposableBean
* @see org.springframework.beans.factory.support.AbstractBeanDefinition#getDestroyMethodName() * @see org.springframework.beans.factory.support.AbstractBeanDefinition#getDestroyMethodName()
* @see DestructionAwareBeanPostProcessor * @see DestructionAwareBeanPostProcessor
@ -123,6 +126,7 @@ public interface Scope {
* E.g. the HttpServletRequest object for key "request". * E.g. the HttpServletRequest object for key "request".
* @param key the contextual key * @param key the contextual key
* @return the corresponding object, or {@code null} if none found * @return the corresponding object, or {@code null} if none found
* @throws IllegalStateException if the underlying scope is not currently active
*/ */
Object resolveContextualObject(String key); Object resolveContextualObject(String key);
@ -139,6 +143,7 @@ public interface Scope {
* underlying storage mechanism has no obvious candidate for such an ID. * underlying storage mechanism has no obvious candidate for such an ID.
* @return the conversation ID, or {@code null} if there is no * @return the conversation ID, or {@code null} if there is no
* conversation ID for the current scope * conversation ID for the current scope
* @throws IllegalStateException if the underlying scope is not currently active
*/ */
String getConversationId(); String getConversationId();

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

@ -500,7 +500,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #instantiateUsingFactoryMethod * @see #instantiateUsingFactoryMethod
* @see #autowireConstructor * @see #autowireConstructor
*/ */
protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final Object[] args) { protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final Object[] args)
throws BeanCreationException {
// Instantiate the bean. // Instantiate the bean.
BeanWrapper instanceWrapper = null; BeanWrapper instanceWrapper = null;
if (mbd.isSingleton()) { if (mbd.isSingleton()) {
@ -515,7 +517,13 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
// Allow post-processors to modify the merged bean definition. // Allow post-processors to modify the merged bean definition.
synchronized (mbd.postProcessingLock) { synchronized (mbd.postProcessingLock) {
if (!mbd.postProcessed) { if (!mbd.postProcessed) {
try {
applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName); applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);
}
catch (Throwable ex) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
"Post-processing of merged bean definition failed", ex);
}
mbd.postProcessed = true; mbd.postProcessed = true;
} }
} }
@ -550,7 +558,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
throw (BeanCreationException) ex; throw (BeanCreationException) ex;
} }
else { else {
throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Initialization of bean failed", ex); throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Initialization of bean failed", ex);
} }
} }
@ -586,7 +595,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
registerDisposableBeanIfNecessary(beanName, bean, mbd); registerDisposableBeanIfNecessary(beanName, bean, mbd);
} }
catch (BeanDefinitionValidationException ex) { catch (BeanDefinitionValidationException ex) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex); throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex);
} }
return exposedObject; return exposedObject;
@ -624,7 +634,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
protected Class<?> determineTargetType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { protected Class<?> determineTargetType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) {
Class<?> targetType = mbd.getTargetType(); Class<?> targetType = mbd.getTargetType();
if (targetType == null) { if (targetType == null) {
targetType = (mbd.getFactoryMethodName() != null ? getTypeForFactoryMethod(beanName, mbd, typesToMatch) : targetType = (mbd.getFactoryMethodName() != null ?
getTypeForFactoryMethod(beanName, mbd, typesToMatch) :
resolveBeanClass(mbd, beanName, typesToMatch)); resolveBeanClass(mbd, beanName, typesToMatch));
if (ObjectUtils.isEmpty(typesToMatch) || getTempClassLoader() == null) { if (ObjectUtils.isEmpty(typesToMatch) || getTempClassLoader() == null) {
mbd.setTargetType(targetType); mbd.setTargetType(targetType);
@ -772,10 +783,11 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
ReflectionUtils.doWithMethods(fbClass, ReflectionUtils.doWithMethods(fbClass,
new ReflectionUtils.MethodCallback() { new ReflectionUtils.MethodCallback() {
@Override @Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { public void doWith(Method method) {
if (method.getName().equals(factoryMethodName) && if (method.getName().equals(factoryMethodName) &&
FactoryBean.class.isAssignableFrom(method.getReturnType())) { FactoryBean.class.isAssignableFrom(method.getReturnType())) {
objectType.value = GenericTypeResolver.resolveReturnTypeArgument(method, FactoryBean.class); objectType.value = GenericTypeResolver.resolveReturnTypeArgument(
method, FactoryBean.class);
} }
} }
}); });
@ -926,13 +938,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @param mbd the merged bean definition for the bean * @param mbd the merged bean definition for the bean
* @param beanType the actual type of the managed bean instance * @param beanType the actual type of the managed bean instance
* @param beanName the name of the bean * @param beanName the name of the bean
* @throws BeansException if any post-processing failed
* @see MergedBeanDefinitionPostProcessor#postProcessMergedBeanDefinition * @see MergedBeanDefinitionPostProcessor#postProcessMergedBeanDefinition
*/ */
protected void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd, Class<?> beanType, String beanName) protected void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd, Class<?> beanType, String beanName) {
throws BeansException {
try {
for (BeanPostProcessor bp : getBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) {
if (bp instanceof MergedBeanDefinitionPostProcessor) { if (bp instanceof MergedBeanDefinitionPostProcessor) {
MergedBeanDefinitionPostProcessor bdp = (MergedBeanDefinitionPostProcessor) bp; MergedBeanDefinitionPostProcessor bdp = (MergedBeanDefinitionPostProcessor) bp;
@ -940,11 +948,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
} }
} }
} }
catch (Exception ex) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
"Post-processing failed of bean type [" + beanType + "] failed", ex);
}
}
/** /**
* Apply before-instantiation post-processors, resolving whether there is a * Apply before-instantiation post-processors, resolving whether there is a
@ -980,12 +983,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @param beanClass the class of the bean to be instantiated * @param beanClass the class of the bean to be instantiated
* @param beanName the name of the bean * @param beanName the name of the bean
* @return the bean object to use instead of a default instance of the target bean, or {@code null} * @return the bean object to use instead of a default instance of the target bean, or {@code null}
* @throws BeansException if any post-processing failed
* @see InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation * @see InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation
*/ */
protected Object applyBeanPostProcessorsBeforeInstantiation(Class<?> beanClass, String beanName) protected Object applyBeanPostProcessorsBeforeInstantiation(Class<?> beanClass, String beanName) {
throws BeansException {
for (BeanPostProcessor bp : getBeanPostProcessors()) { for (BeanPostProcessor bp : getBeanPostProcessors()) {
if (bp instanceof InstantiationAwareBeanPostProcessor) { if (bp instanceof InstantiationAwareBeanPostProcessor) {
InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp; InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;
@ -1106,7 +1106,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
return bw; return bw;
} }
catch (Throwable ex) { catch (Throwable ex) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex); throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex);
} }
} }
@ -1658,7 +1659,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* methods with arguments. * methods with arguments.
* @see #invokeInitMethods * @see #invokeInitMethods
*/ */
protected void invokeCustomInitMethod(String beanName, final Object bean, RootBeanDefinition mbd) throws Throwable { protected void invokeCustomInitMethod(String beanName, final Object bean, RootBeanDefinition mbd)
throws Throwable {
String initMethodName = mbd.getInitMethodName(); String initMethodName = mbd.getInitMethodName();
final Method initMethod = (mbd.isNonPublicAccessAllowed() ? final Method initMethod = (mbd.isNonPublicAccessAllowed() ?
BeanUtils.findMethod(bean.getClass(), initMethodName) : BeanUtils.findMethod(bean.getClass(), initMethodName) :

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

@ -287,13 +287,13 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
// Guarantee initialization of beans that the current bean depends on. // Guarantee initialization of beans that the current bean depends on.
String[] dependsOn = mbd.getDependsOn(); String[] dependsOn = mbd.getDependsOn();
if (dependsOn != null) { if (dependsOn != null) {
for (String dependsOnBean : dependsOn) { for (String dep : dependsOn) {
if (isDependent(beanName, dependsOnBean)) { if (isDependent(beanName, dep)) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName, throw new BeanCreationException(mbd.getResourceDescription(), beanName,
"Circular depends-on relationship between '" + beanName + "' and '" + dependsOnBean + "'"); "Circular depends-on relationship between '" + beanName + "' and '" + dep + "'");
} }
registerDependentBean(dependsOnBean, beanName); registerDependentBean(dep, beanName);
getBean(dependsOnBean); getBean(dep);
} }
} }
@ -460,19 +460,19 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
return false; return false;
} }
if (isFactoryBean(beanName, mbd)) { if (isFactoryBean(beanName, mbd)) {
final FactoryBean<?> factoryBean = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName); final FactoryBean<?> fb = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName);
if (System.getSecurityManager() != null) { if (System.getSecurityManager() != null) {
return AccessController.doPrivileged(new PrivilegedAction<Boolean>() { return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override @Override
public Boolean run() { public Boolean run() {
return ((factoryBean instanceof SmartFactoryBean && ((SmartFactoryBean<?>) factoryBean).isPrototype()) || return ((fb instanceof SmartFactoryBean && ((SmartFactoryBean<?>) fb).isPrototype()) ||
!factoryBean.isSingleton()); !fb.isSingleton());
} }
}, getAccessControlContext()); }, getAccessControlContext());
} }
else { else {
return ((factoryBean instanceof SmartFactoryBean && ((SmartFactoryBean<?>) factoryBean).isPrototype()) || return ((fb instanceof SmartFactoryBean && ((SmartFactoryBean<?>) fb).isPrototype()) ||
!factoryBean.isSingleton()); !fb.isSingleton());
} }
} }
else { else {
@ -800,12 +800,15 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
@Override @Override
public String resolveEmbeddedValue(String value) { public String resolveEmbeddedValue(String value) {
if (value == null) {
return null;
}
String result = value; String result = value;
for (StringValueResolver resolver : this.embeddedValueResolvers) { for (StringValueResolver resolver : this.embeddedValueResolvers) {
result = resolver.resolveStringValue(result);
if (result == null) { if (result == null) {
return null; return null;
} }
result = resolver.resolveStringValue(result);
} }
return result; return result;
} }
@ -1045,11 +1048,11 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
* Destroy the given bean instance (usually a prototype instance * Destroy the given bean instance (usually a prototype instance
* obtained from this factory) according to the given bean definition. * obtained from this factory) according to the given bean definition.
* @param beanName the name of the bean definition * @param beanName the name of the bean definition
* @param beanInstance the bean instance to destroy * @param bean the bean instance to destroy
* @param mbd the merged bean definition * @param mbd the merged bean definition
*/ */
protected void destroyBean(String beanName, Object beanInstance, RootBeanDefinition mbd) { protected void destroyBean(String beanName, Object bean, RootBeanDefinition mbd) {
new DisposableBeanAdapter(beanInstance, beanName, mbd, getBeanPostProcessors(), getAccessControlContext()).destroy(); new DisposableBeanAdapter(bean, beanName, mbd, getBeanPostProcessors(), getAccessControlContext()).destroy();
} }
@Override @Override
@ -1230,12 +1233,13 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
pbd = getMergedBeanDefinition(parentBeanName); pbd = getMergedBeanDefinition(parentBeanName);
} }
else { else {
if (getParentBeanFactory() instanceof ConfigurableBeanFactory) { BeanFactory parent = getParentBeanFactory();
pbd = ((ConfigurableBeanFactory) getParentBeanFactory()).getMergedBeanDefinition(parentBeanName); if (parent instanceof ConfigurableBeanFactory) {
pbd = ((ConfigurableBeanFactory) parent).getMergedBeanDefinition(parentBeanName);
} }
else { else {
throw new NoSuchBeanDefinitionException(bd.getParentName(), throw new NoSuchBeanDefinitionException(parentBeanName,
"Parent name '" + bd.getParentName() + "' is equal to bean name '" + beanName + "Parent name '" + parentBeanName + "' is equal to bean name '" + beanName +
"': cannot be resolved without an AbstractBeanFactory parent"); "': cannot be resolved without an AbstractBeanFactory parent");
} }
} }
@ -1351,12 +1355,14 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex);
} }
catch (LinkageError err) { catch (LinkageError ex) {
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex);
} }
} }
private Class<?> doResolveBeanClass(RootBeanDefinition mbd, Class<?>... typesToMatch) throws ClassNotFoundException { private Class<?> doResolveBeanClass(RootBeanDefinition mbd, Class<?>... typesToMatch)
throws ClassNotFoundException {
ClassLoader beanClassLoader = getBeanClassLoader(); ClassLoader beanClassLoader = getBeanClassLoader();
ClassLoader classLoaderToUse = beanClassLoader; ClassLoader classLoaderToUse = beanClassLoader;
if (!ObjectUtils.isEmpty(typesToMatch)) { if (!ObjectUtils.isEmpty(typesToMatch)) {

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

@ -214,7 +214,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
if (singletonObject == null) { if (singletonObject == null) {
if (this.singletonsCurrentlyInDestruction) { if (this.singletonsCurrentlyInDestruction) {
throw new BeanCreationNotAllowedException(beanName, throw new BeanCreationNotAllowedException(beanName,
"Singleton bean creation not allowed while the singletons of this factory are in destruction " + "Singleton bean creation not allowed while singletons of this factory are in destruction " +
"(Do not request a bean from a BeanFactory in a destroy method implementation!)"); "(Do not request a bean from a BeanFactory in a destroy method implementation!)");
} }
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {

152
spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.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.
@ -50,52 +50,48 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
private final ApplicationContext context = mock(ApplicationContext.class); private final ApplicationContext context = mock(ApplicationContext.class);
@Test @Test
public void rawListener() { public void rawListener() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleRaw", ApplicationEvent.class);
"handleRaw", ApplicationEvent.class);
supportsEventType(true, method, getGenericApplicationEventType("applicationEvent")); supportsEventType(true, method, getGenericApplicationEventType("applicationEvent"));
} }
@Test @Test
public void rawListenerWithGenericEvent() { public void rawListenerWithGenericEvent() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleRaw", ApplicationEvent.class);
"handleRaw", ApplicationEvent.class);
supportsEventType(true, method, getGenericApplicationEventType("stringEvent")); supportsEventType(true, method, getGenericApplicationEventType("stringEvent"));
} }
@Test @Test
public void genericListener() { public void genericListener() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
supportsEventType(true, method, getGenericApplicationEventType("stringEvent")); supportsEventType(true, method, getGenericApplicationEventType("stringEvent"));
} }
@Test @Test
public void genericListenerWrongParameterizedType() { public void genericListenerWrongParameterizedType() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
supportsEventType(false, method, getGenericApplicationEventType("longEvent")); supportsEventType(false, method, getGenericApplicationEventType("longEvent"));
} }
@Test @Test
public void listenerWithPayloadAndGenericInformation() { public void listenerWithPayloadAndGenericInformation() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
"handleString", String.class);
supportsEventType(true, method, createGenericEventType(String.class)); supportsEventType(true, method, createGenericEventType(String.class));
} }
@Test @Test
public void listenerWithInvalidPayloadAndGenericInformation() { public void listenerWithInvalidPayloadAndGenericInformation() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
"handleString", String.class);
supportsEventType(false, method, createGenericEventType(Integer.class)); supportsEventType(false, method, createGenericEventType(Integer.class));
} }
@Test @Test
public void listenerWithPayloadTypeErasure() { // Always accept such event when the type is unknown public void listenerWithPayloadTypeErasure() { // Always accept such event when the type is unknown
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
"handleString", String.class);
supportsEventType(true, method, ResolvableType.forClass(PayloadApplicationEvent.class)); supportsEventType(true, method, ResolvableType.forClass(PayloadApplicationEvent.class));
} }
@ -108,36 +104,32 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void listenerWithSubTypeSeveralGenericsResolved() { public void listenerWithSubTypeSeveralGenericsResolved() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
"handleString", String.class);
supportsEventType(true, method, ResolvableType.forClass(PayloadStringTestEvent.class)); supportsEventType(true, method, ResolvableType.forClass(PayloadStringTestEvent.class));
} }
@Test @Test
public void listenerWithAnnotationValue() { public void listenerWithAnnotationValue() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationValue");
"handleStringAnnotationValue");
supportsEventType(true, method, createGenericEventType(String.class)); supportsEventType(true, method, createGenericEventType(String.class));
} }
@Test @Test
public void listenerWithAnnotationClasses() { public void listenerWithAnnotationClasses() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationClasses");
"handleStringAnnotationClasses");
supportsEventType(true, method, createGenericEventType(String.class)); supportsEventType(true, method, createGenericEventType(String.class));
} }
@Test @Test
public void listenerWithAnnotationValueAndParameter() { public void listenerWithAnnotationValueAndParameter() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleStringAnnotationValueAndParameter", String.class); SampleEvents.class, "handleStringAnnotationValueAndParameter", String.class);
supportsEventType(true, method, createGenericEventType(String.class)); supportsEventType(true, method, createGenericEventType(String.class));
} }
@Test @Test
public void listenerWithSeveralTypes() { public void listenerWithSeveralTypes() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringOrInteger");
"handleStringOrInteger");
supportsEventType(true, method, createGenericEventType(String.class)); supportsEventType(true, method, createGenericEventType(String.class));
supportsEventType(true, method, createGenericEventType(Integer.class)); supportsEventType(true, method, createGenericEventType(Integer.class));
supportsEventType(false, method, createGenericEventType(Double.class)); supportsEventType(false, method, createGenericEventType(Double.class));
@ -145,51 +137,47 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void listenerWithTooManyParameters() { public void listenerWithTooManyParameters() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"tooManyParameters", String.class, String.class); SampleEvents.class, "tooManyParameters", String.class, String.class);
this.thrown.expect(IllegalStateException.class);
thrown.expect(IllegalStateException.class);
createTestInstance(method); createTestInstance(method);
} }
@Test @Test
public void listenerWithNoParameter() { public void listenerWithNoParameter() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "noParameter");
"noParameter"); this.thrown.expect(IllegalStateException.class);
thrown.expect(IllegalStateException.class);
createTestInstance(method); createTestInstance(method);
} }
@Test @Test
public void listenerWithMoreThanOneParameter() { public void listenerWithMoreThanOneParameter() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"moreThanOneParameter", String.class, Integer.class); SampleEvents.class, "moreThanOneParameter", String.class, Integer.class);
this.thrown.expect(IllegalStateException.class);
thrown.expect(IllegalStateException.class);
createTestInstance(method); createTestInstance(method);
} }
@Test @Test
public void defaultOrder() { public void defaultOrder() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
ApplicationListenerMethodAdapter adapter = createTestInstance(method); ApplicationListenerMethodAdapter adapter = createTestInstance(method);
assertEquals(0, adapter.getOrder()); assertEquals(0, adapter.getOrder());
} }
@Test @Test
public void specifiedOrder() { public void specifiedOrder() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleRaw", ApplicationEvent.class); SampleEvents.class, "handleRaw", ApplicationEvent.class);
ApplicationListenerMethodAdapter adapter = createTestInstance(method); ApplicationListenerMethodAdapter adapter = createTestInstance(method);
assertEquals(42, adapter.getOrder()); assertEquals(42, adapter.getOrder());
} }
@Test @Test
public void invokeListener() { public void invokeListener() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("test"); GenericTestEvent<String> event = createGenericTestEvent("test");
invokeListener(method, event); invokeListener(method, event);
verify(this.sampleEvents, times(1)).handleGenericString(event); verify(this.sampleEvents, times(1)).handleGenericString(event);
@ -197,8 +185,8 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerWithGenericEvent() { public void invokeListenerWithGenericEvent() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
GenericTestEvent<String> event = new SmartGenericTestEvent<>(this, "test"); GenericTestEvent<String> event = new SmartGenericTestEvent<>(this, "test");
invokeListener(method, event); invokeListener(method, event);
verify(this.sampleEvents, times(1)).handleGenericString(event); verify(this.sampleEvents, times(1)).handleGenericString(event);
@ -206,8 +194,8 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerWithGenericPayload() { public void invokeListenerWithGenericPayload() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleGenericStringPayload", EntityWrapper.class); SampleEvents.class, "handleGenericStringPayload", EntityWrapper.class);
EntityWrapper<String> payload = new EntityWrapper<>("test"); EntityWrapper<String> payload = new EntityWrapper<>("test");
invokeListener(method, new PayloadApplicationEvent<>(this, payload)); invokeListener(method, new PayloadApplicationEvent<>(this, payload));
verify(this.sampleEvents, times(1)).handleGenericStringPayload(payload); verify(this.sampleEvents, times(1)).handleGenericStringPayload(payload);
@ -215,8 +203,8 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerWithWrongGenericPayload() { public void invokeListenerWithWrongGenericPayload() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod
"handleGenericStringPayload", EntityWrapper.class); (SampleEvents.class, "handleGenericStringPayload", EntityWrapper.class);
EntityWrapper<Integer> payload = new EntityWrapper<>(123); EntityWrapper<Integer> payload = new EntityWrapper<>(123);
invokeListener(method, new PayloadApplicationEvent<>(this, payload)); invokeListener(method, new PayloadApplicationEvent<>(this, payload));
verify(this.sampleEvents, times(0)).handleGenericStringPayload(any()); verify(this.sampleEvents, times(0)).handleGenericStringPayload(any());
@ -224,8 +212,8 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerWithAnyGenericPayload() { public void invokeListenerWithAnyGenericPayload() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleGenericAnyPayload", EntityWrapper.class); SampleEvents.class, "handleGenericAnyPayload", EntityWrapper.class);
EntityWrapper<String> payload = new EntityWrapper<>("test"); EntityWrapper<String> payload = new EntityWrapper<>("test");
invokeListener(method, new PayloadApplicationEvent<>(this, payload)); invokeListener(method, new PayloadApplicationEvent<>(this, payload));
verify(this.sampleEvents, times(1)).handleGenericAnyPayload(payload); verify(this.sampleEvents, times(1)).handleGenericAnyPayload(payload);
@ -233,24 +221,24 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerRuntimeException() { public void invokeListenerRuntimeException() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"generateRuntimeException", GenericTestEvent.class); SampleEvents.class, "generateRuntimeException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail"); GenericTestEvent<String> event = createGenericTestEvent("fail");
thrown.expect(IllegalStateException.class); this.thrown.expect(IllegalStateException.class);
thrown.expectMessage("Test exception"); this.thrown.expectMessage("Test exception");
thrown.expectCause(is(isNull(Throwable.class))); this.thrown.expectCause(is((Throwable) isNull()));
invokeListener(method, event); invokeListener(method, event);
} }
@Test @Test
public void invokeListenerCheckedException() { public void invokeListenerCheckedException() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"generateCheckedException", GenericTestEvent.class); SampleEvents.class, "generateCheckedException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail"); GenericTestEvent<String> event = createGenericTestEvent("fail");
thrown.expect(UndeclaredThrowableException.class); this.thrown.expect(UndeclaredThrowableException.class);
thrown.expectCause(is(instanceOf(IOException.class))); this.thrown.expectCause(is(instanceOf(IOException.class)));
invokeListener(method, event); invokeListener(method, event);
} }
@ -262,18 +250,18 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
proxyFactory.addInterface(SimpleService.class); proxyFactory.addInterface(SimpleService.class);
Object bean = proxyFactory.getProxy(getClass().getClassLoader()); Object bean = proxyFactory.getProxy(getClass().getClassLoader());
Method method = ReflectionUtils.findMethod(InvalidProxyTestBean.class, "handleIt2", ApplicationEvent.class); Method method = ReflectionUtils.findMethod(
InvalidProxyTestBean.class, "handleIt2", ApplicationEvent.class);
StaticApplicationListenerMethodAdapter listener = StaticApplicationListenerMethodAdapter listener =
new StaticApplicationListenerMethodAdapter(method, bean); new StaticApplicationListenerMethodAdapter(method, bean);
thrown.expect(IllegalStateException.class); this.thrown.expect(IllegalStateException.class);
thrown.expectMessage("handleIt2"); this.thrown.expectMessage("handleIt2");
listener.onApplicationEvent(createGenericTestEvent("test")); listener.onApplicationEvent(createGenericTestEvent("test"));
} }
@Test @Test
public void invokeListenerWithPayload() { public void invokeListenerWithPayload() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
"handleString", String.class);
PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test"); PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
invokeListener(method, event); invokeListener(method, event);
verify(this.sampleEvents, times(1)).handleString("test"); verify(this.sampleEvents, times(1)).handleString("test");
@ -281,8 +269,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerWithPayloadWrongType() { public void invokeListenerWithPayloadWrongType() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
"handleString", String.class);
PayloadApplicationEvent<Long> event = new PayloadApplicationEvent<>(this, 123L); PayloadApplicationEvent<Long> event = new PayloadApplicationEvent<>(this, 123L);
invokeListener(method, event); invokeListener(method, event);
verify(this.sampleEvents, never()).handleString(anyString()); verify(this.sampleEvents, never()).handleString(anyString());
@ -290,8 +277,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerWithAnnotationValue() { public void invokeListenerWithAnnotationValue() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationClasses");
"handleStringAnnotationClasses");
PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test"); PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
invokeListener(method, event); invokeListener(method, event);
verify(this.sampleEvents, times(1)).handleStringAnnotationClasses(); verify(this.sampleEvents, times(1)).handleStringAnnotationClasses();
@ -299,8 +285,8 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerWithAnnotationValueAndParameter() { public void invokeListenerWithAnnotationValueAndParameter() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleStringAnnotationValueAndParameter", String.class); SampleEvents.class, "handleStringAnnotationValueAndParameter", String.class);
PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test"); PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
invokeListener(method, event); invokeListener(method, event);
verify(this.sampleEvents, times(1)).handleStringAnnotationValueAndParameter("test"); verify(this.sampleEvents, times(1)).handleStringAnnotationValueAndParameter("test");
@ -308,8 +294,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Test @Test
public void invokeListenerWithSeveralTypes() { public void invokeListenerWithSeveralTypes() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringOrInteger");
"handleStringOrInteger");
PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test"); PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
invokeListener(method, event); invokeListener(method, event);
verify(this.sampleEvents, times(1)).handleStringOrInteger(); verify(this.sampleEvents, times(1)).handleStringOrInteger();
@ -321,11 +306,10 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
verify(this.sampleEvents, times(2)).handleStringOrInteger(); verify(this.sampleEvents, times(2)).handleStringOrInteger();
} }
@Test @Test
public void beanInstanceRetrievedAtEveryInvocation() { public void beanInstanceRetrievedAtEveryInvocation() {
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(
"handleGenericString", GenericTestEvent.class); SampleEvents.class, "handleGenericString", GenericTestEvent.class);
when(this.context.getBean("testBean")).thenReturn(this.sampleEvents); when(this.context.getBean("testBean")).thenReturn(this.sampleEvents);
ApplicationListenerMethodAdapter listener = new ApplicationListenerMethodAdapter( ApplicationListenerMethodAdapter listener = new ApplicationListenerMethodAdapter(
"testBean", GenericTestEvent.class, method); "testBean", GenericTestEvent.class, method);
@ -342,6 +326,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
verify(this.context, times(2)).getBean("testBean"); verify(this.context, times(2)).getBean("testBean");
} }
private void supportsEventType(boolean match, Method method, ResolvableType eventType) { private void supportsEventType(boolean match, Method method, ResolvableType eventType) {
ApplicationListenerMethodAdapter adapter = createTestInstance(method); ApplicationListenerMethodAdapter adapter = createTestInstance(method);
assertEquals("Wrong match for event '" + eventType + "' on " + method, assertEquals("Wrong match for event '" + eventType + "' on " + method,
@ -361,8 +346,8 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
return ResolvableType.forClassWithGenerics(PayloadApplicationEvent.class, payloadType); return ResolvableType.forClassWithGenerics(PayloadApplicationEvent.class, payloadType);
} }
private static class StaticApplicationListenerMethodAdapter
extends ApplicationListenerMethodAdapter { private static class StaticApplicationListenerMethodAdapter extends ApplicationListenerMethodAdapter {
private final Object targetBean; private final Object targetBean;
@ -373,14 +358,13 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Override @Override
public Object getTargetBean() { public Object getTargetBean() {
return targetBean; return this.targetBean;
} }
} }
private static class SampleEvents { private static class SampleEvents {
@EventListener @EventListener
@Order(42) @Order(42)
public void handleRaw(ApplicationEvent event) { public void handleRaw(ApplicationEvent event) {
@ -449,13 +433,15 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
} }
interface SimpleService { interface SimpleService {
void handleIt(ApplicationEvent event); void handleIt(ApplicationEvent event);
} }
private static class EntityWrapper<T> implements ResolvableTypeProvider { private static class EntityWrapper<T> implements ResolvableTypeProvider {
private final T entity; private final T entity;
public EntityWrapper(T entity) { public EntityWrapper(T entity) {
@ -468,6 +454,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
} }
static class InvalidProxyTestBean implements SimpleService { static class InvalidProxyTestBean implements SimpleService {
@Override @Override
@ -479,6 +466,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
} }
@SuppressWarnings({"unused", "serial"}) @SuppressWarnings({"unused", "serial"})
static class PayloadTestEvent<V, T> extends PayloadApplicationEvent<T> { static class PayloadTestEvent<V, T> extends PayloadApplicationEvent<T> {
@ -490,8 +478,10 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
} }
} }
@SuppressWarnings({ "serial" }) @SuppressWarnings({ "serial" })
static class PayloadStringTestEvent extends PayloadTestEvent<Long, String> { static class PayloadStringTestEvent extends PayloadTestEvent<Long, String> {
public PayloadStringTestEvent(Object source, String payload, Long something) { public PayloadStringTestEvent(Object source, String payload, Long something) {
super(source, payload, something); super(source, payload, something);
} }

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

@ -607,6 +607,7 @@ public abstract class ReflectionUtils {
* @see Class#getDeclaredMethods() * @see Class#getDeclaredMethods()
*/ */
private static Method[] getDeclaredMethods(Class<?> clazz) { private static Method[] getDeclaredMethods(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
Method[] result = declaredMethodsCache.get(clazz); Method[] result = declaredMethodsCache.get(clazz);
if (result == null) { if (result == null) {
Method[] declaredMethods = clazz.getDeclaredMethods(); Method[] declaredMethods = clazz.getDeclaredMethods();
@ -708,6 +709,7 @@ public abstract class ReflectionUtils {
* @see Class#getDeclaredFields() * @see Class#getDeclaredFields()
*/ */
private static Field[] getDeclaredFields(Class<?> clazz) { private static Field[] getDeclaredFields(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
Field[] result = declaredFieldsCache.get(clazz); Field[] result = declaredFieldsCache.get(clazz);
if (result == null) { if (result == null) {
result = clazz.getDeclaredFields(); result = clazz.getDeclaredFields();

9
spring-web/src/main/java/org/springframework/http/client/AbstractAsyncClientHttpRequest.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 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.
@ -73,12 +73,11 @@ abstract class AbstractAsyncClientHttpRequest implements AsyncClientHttpRequest
protected abstract OutputStream getBodyInternal(HttpHeaders headers) throws IOException; protected abstract OutputStream getBodyInternal(HttpHeaders headers) throws IOException;
/** /**
* Abstract template method that writes the given headers and content to the HTTP * Abstract template method that writes the given headers and content to the HTTP request.
* request.
* @param headers the HTTP headers * @param headers the HTTP headers
* @return the response object for the executed request * @return the response object for the executed request
*/ */
protected abstract ListenableFuture<ClientHttpResponse> executeInternal( protected abstract ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers)
HttpHeaders headers) throws IOException; throws IOException;
} }

30
spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 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.
@ -34,8 +34,8 @@ public class HttpClientErrorException extends HttpStatusCodeException {
/** /**
* Construct a new instance of {@code HttpClientErrorException} based on an * Construct a new instance of {@code HttpClientErrorException} based on
* {@link HttpStatus}. * an {@link HttpStatus}.
* @param statusCode the status code * @param statusCode the status code
*/ */
public HttpClientErrorException(HttpStatus statusCode) { public HttpClientErrorException(HttpStatus statusCode) {
@ -43,8 +43,8 @@ public class HttpClientErrorException extends HttpStatusCodeException {
} }
/** /**
* Construct a new instance of {@code HttpClientErrorException} based on an * Construct a new instance of {@code HttpClientErrorException} based on
* {@link HttpStatus} and status text. * an {@link HttpStatus} and status text.
* @param statusCode the status code * @param statusCode the status code
* @param statusText the status text * @param statusText the status text
*/ */
@ -53,30 +53,32 @@ public class HttpClientErrorException extends HttpStatusCodeException {
} }
/** /**
* Construct a new instance of {@code HttpClientErrorException} based on an * Construct a new instance of {@code HttpClientErrorException} based on
* {@link HttpStatus}, status text, and response body content. * an {@link HttpStatus}, status text, and response body content.
* @param statusCode the status code * @param statusCode the status code
* @param statusText the status text * @param statusText the status text
* @param responseBody the response body content, may be {@code null} * @param responseBody the response body content (may be {@code null})
* @param responseCharset the response body charset, may be {@code null} * @param responseCharset the response body charset (may be {@code null})
*/ */
public HttpClientErrorException(HttpStatus statusCode, String statusText, public HttpClientErrorException(HttpStatus statusCode, String statusText,
byte[] responseBody, Charset responseCharset) { byte[] responseBody, Charset responseCharset) {
super(statusCode, statusText, responseBody, responseCharset); super(statusCode, statusText, responseBody, responseCharset);
} }
/** /**
* Construct a new instance of {@code HttpClientErrorException} based on an * Construct a new instance of {@code HttpClientErrorException} based on
* {@link HttpStatus}, status text, and response body content. * an {@link HttpStatus}, status text, and response body content.
* @param statusCode the status code * @param statusCode the status code
* @param statusText the status text * @param statusText the status text
* @param responseHeaders the response headers, may be {@code null} * @param responseHeaders the response headers (may be {@code null})
* @param responseBody the response body content, may be {@code null} * @param responseBody the response body content (may be {@code null})
* @param responseCharset the response body charset, may be {@code null} * @param responseCharset the response body charset (may be {@code null})
* @since 3.1.2 * @since 3.1.2
*/ */
public HttpClientErrorException(HttpStatus statusCode, String statusText, public HttpClientErrorException(HttpStatus statusCode, String statusText,
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
super(statusCode, statusText, responseHeaders, responseBody, responseCharset); super(statusCode, statusText, responseHeaders, responseBody, responseCharset);
} }

33
spring-web/src/main/java/org/springframework/web/client/HttpServerErrorException.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 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.
@ -25,8 +25,8 @@ import org.springframework.http.HttpStatus;
* Exception thrown when an HTTP 5xx is received. * Exception thrown when an HTTP 5xx is received.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @see DefaultResponseErrorHandler
* @since 3.0 * @since 3.0
* @see DefaultResponseErrorHandler
*/ */
public class HttpServerErrorException extends HttpStatusCodeException { public class HttpServerErrorException extends HttpStatusCodeException {
@ -34,8 +34,8 @@ public class HttpServerErrorException extends HttpStatusCodeException {
/** /**
* Construct a new instance of {@code HttpServerErrorException} based on an * Construct a new instance of {@code HttpServerErrorException} based on
* {@link HttpStatus}. * an {@link HttpStatus}.
* @param statusCode the status code * @param statusCode the status code
*/ */
public HttpServerErrorException(HttpStatus statusCode) { public HttpServerErrorException(HttpStatus statusCode) {
@ -43,8 +43,8 @@ public class HttpServerErrorException extends HttpStatusCodeException {
} }
/** /**
* Construct a new instance of {@code HttpServerErrorException} based on an * Construct a new instance of {@code HttpServerErrorException} based on
* {@link HttpStatus} and status text. * an {@link HttpStatus} and status text.
* @param statusCode the status code * @param statusCode the status code
* @param statusText the status text * @param statusText the status text
*/ */
@ -53,31 +53,34 @@ public class HttpServerErrorException extends HttpStatusCodeException {
} }
/** /**
* Construct a new instance of {@code HttpServerErrorException} based on an * Construct a new instance of {@code HttpServerErrorException} based on
* {@link HttpStatus}, status text, and response body content. * an {@link HttpStatus}, status text, and response body content.
* @param statusCode the status code * @param statusCode the status code
* @param statusText the status text * @param statusText the status text
* @param responseBody the response body content, may be {@code null} * @param responseBody the response body content (may be {@code null})
* @param responseCharset the response body charset, may be {@code null} * @param responseCharset the response body charset (may be {@code null})
* @since 3.0.5 * @since 3.0.5
*/ */
public HttpServerErrorException(HttpStatus statusCode, String statusText, public HttpServerErrorException(HttpStatus statusCode, String statusText,
byte[] responseBody, Charset responseCharset) { byte[] responseBody, Charset responseCharset) {
super(statusCode, statusText, responseBody, responseCharset); super(statusCode, statusText, responseBody, responseCharset);
} }
/** /**
* Construct a new instance of {@code HttpServerErrorException} based on a * Construct a new instance of {@code HttpServerErrorException} based on
* {@link HttpStatus}, status text, and response body content. * an {@link HttpStatus}, status text, and response body content.
* @param statusCode the status code * @param statusCode the status code
* @param statusText the status text * @param statusText the status text
* @param responseHeaders the response headers, may be {@code null} * @param responseHeaders the response headers (may be {@code null})
* @param responseBody the response body content, may be {@code null} * @param responseBody the response body content (may be {@code null})
* @param responseCharset the response body charset, may be {@code null} * @param responseCharset the response body charset (may be {@code null})
* @since 3.1.2 * @since 3.1.2
*/ */
public HttpServerErrorException(HttpStatus statusCode, String statusText, public HttpServerErrorException(HttpStatus statusCode, String statusText,
HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) { HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset) {
super(statusCode, statusText, responseHeaders, responseBody, responseCharset); super(statusCode, statusText, responseHeaders, responseBody, responseCharset);
} }
} }

Loading…
Cancel
Save