diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncUncaughtExceptionHandler.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncUncaughtExceptionHandler.java index 1d54b0da0ba..933e3024c5f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncUncaughtExceptionHandler.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncUncaughtExceptionHandler.java @@ -19,11 +19,11 @@ package org.springframework.aop.interceptor; import java.lang.reflect.Method; /** - * A strategy for handling uncaught exception thrown by asynchronous methods. + * A strategy for handling uncaught exceptions thrown from asynchronous methods. * *
An asynchronous method usually returns a {@link java.util.concurrent.Future}
- * instance that gives access to the underlying exception. When the method
- * does not provide that return type, this handler can be used to managed such
+ * instance that gives access to the underlying exception. When the method does
+ * not provide that return type, this handler can be used to managed such
* uncaught exceptions.
*
* @author Stephane Nicoll
@@ -32,11 +32,11 @@ import java.lang.reflect.Method;
public interface AsyncUncaughtExceptionHandler {
/**
- * Handle the given uncaught error thrown while processing
- * an asynchronous method.
- * @param ex the exception thrown by invoking the async operation
- * @param method the async operation
+ * Handle the given uncaught exception thrown from an asynchronous method.
+ * @param ex the exception thrown from the asynchronous method
+ * @param method the asynchronous method
* @param params the parameters used to invoked the method
*/
void handleUncaughtException(Throwable ex, Method method, Object... params);
+
}
diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AnnotationAsyncExecutionInterceptor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AnnotationAsyncExecutionInterceptor.java
index 61ea21a0d89..8519711c58b 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AnnotationAsyncExecutionInterceptor.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AnnotationAsyncExecutionInterceptor.java
@@ -40,28 +40,28 @@ import org.springframework.core.annotation.AnnotationUtils;
public class AnnotationAsyncExecutionInterceptor extends AsyncExecutionInterceptor {
/**
- * Create a new {@code AnnotationAsyncExecutionInterceptor} with the given executor.
+ * Create a new {@code AnnotationAsyncExecutionInterceptor} with the given executor
+ * and a simple {@link AsyncUncaughtExceptionHandler}.
* @param defaultExecutor the executor to be used by default if no more specific
* executor has been qualified at the method level using {@link Async#value()}
- * @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use to
- * handle exceptions thrown by asynchronous method executions with {@code void}
- * return type
*/
- public AnnotationAsyncExecutionInterceptor(Executor defaultExecutor,
- AsyncUncaughtExceptionHandler exceptionHandler) {
- super(defaultExecutor, exceptionHandler);
+ public AnnotationAsyncExecutionInterceptor(Executor defaultExecutor) {
+ this(defaultExecutor, new SimpleAsyncUncaughtExceptionHandler());
}
/**
- * Create a new {@code AnnotationAsyncExecutionInterceptor} with the given executor
- * and a simple {@link AsyncUncaughtExceptionHandler}.
+ * Create a new {@code AnnotationAsyncExecutionInterceptor} with the given executor.
* @param defaultExecutor the executor to be used by default if no more specific
* executor has been qualified at the method level using {@link Async#value()}
+ * @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use to
+ * handle exceptions thrown by asynchronous method executions with {@code void}
+ * return type
*/
- public AnnotationAsyncExecutionInterceptor(Executor defaultExecutor) {
- this(defaultExecutor, new SimpleAsyncUncaughtExceptionHandler());
+ public AnnotationAsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
+ super(defaultExecutor, exceptionHandler);
}
+
/**
* Return the qualifier or bean name of the executor to be used when executing the
* given method, specified via {@link Async#value} at the method or declaring
diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java
index b8082630322..549584f3f49 100644
--- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java
+++ b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorTests.java
@@ -23,6 +23,7 @@ import java.lang.annotation.Target;
import org.junit.Before;
import org.junit.Test;
+
import org.springframework.aop.scope.ScopedObject;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.FactoryBean;
@@ -86,8 +87,7 @@ public class ConfigurationClassPostProcessorTests {
*/
@Test
public void alreadyLoadedConfigurationClasses() {
- beanFactory.registerBeanDefinition("unloadedConfig", new RootBeanDefinition(UnloadedConfig.class.getName(),
- null, null));
+ beanFactory.registerBeanDefinition("unloadedConfig", new RootBeanDefinition(UnloadedConfig.class.getName()));
beanFactory.registerBeanDefinition("loadedConfig", new RootBeanDefinition(LoadedConfig.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
@@ -126,56 +126,56 @@ public class ConfigurationClassPostProcessorTests {
@Test
public void postProcessorWorksWithComposedConfigurationWithAttributeOverridesUsingReflection() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
- ComposedConfigurationWithAttributeOverridesClass.class);
+ ComposedConfigurationWithAttributeOverridesClass.class);
assertSupportForComposedAnnotation(beanDefinition);
}
@Test
public void postProcessorWorksWithComposedConfigurationWithAttributeOverridesUsingAsm() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
- ComposedConfigurationWithAttributeOverridesClass.class.getName());
+ ComposedConfigurationWithAttributeOverridesClass.class.getName());
assertSupportForComposedAnnotation(beanDefinition);
}
@Test
public void postProcessorWorksWithComposedComposedConfigurationWithAttributeOverridesUsingReflection() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
- ComposedComposedConfigurationWithAttributeOverridesClass.class);
+ ComposedComposedConfigurationWithAttributeOverridesClass.class);
assertSupportForComposedAnnotation(beanDefinition);
}
@Test
public void postProcessorWorksWithComposedComposedConfigurationWithAttributeOverridesUsingAsm() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
- ComposedComposedConfigurationWithAttributeOverridesClass.class.getName());
+ ComposedComposedConfigurationWithAttributeOverridesClass.class.getName());
assertSupportForComposedAnnotation(beanDefinition);
}
@Test
public void postProcessorWorksWithMetaComponentScanConfigurationWithAttributeOverridesUsingReflection() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
- MetaComponentScanConfigurationWithAttributeOverridesClass.class);
+ MetaComponentScanConfigurationWithAttributeOverridesClass.class);
assertSupportForComposedAnnotation(beanDefinition);
}
@Test
public void postProcessorWorksWithMetaComponentScanConfigurationWithAttributeOverridesUsingAsm() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
- MetaComponentScanConfigurationWithAttributeOverridesClass.class.getName());
+ MetaComponentScanConfigurationWithAttributeOverridesClass.class.getName());
assertSupportForComposedAnnotation(beanDefinition);
}
@Test
public void postProcessorWorksWithMetaComponentScanConfigurationWithAttributeOverridesSubclassUsingReflection() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
- SubMetaComponentScanConfigurationWithAttributeOverridesClass.class);
+ SubMetaComponentScanConfigurationWithAttributeOverridesClass.class);
assertSupportForComposedAnnotation(beanDefinition);
}
@Test
public void postProcessorWorksWithMetaComponentScanConfigurationWithAttributeOverridesSubclassUsingAsm() {
RootBeanDefinition beanDefinition = new RootBeanDefinition(
- SubMetaComponentScanConfigurationWithAttributeOverridesClass.class.getName());
+ SubMetaComponentScanConfigurationWithAttributeOverridesClass.class.getName());
assertSupportForComposedAnnotation(beanDefinition);
}
@@ -208,8 +208,8 @@ public class ConfigurationClassPostProcessorTests {
public void postProcessorDoesNotOverrideRegularBeanDefinitionsEvenWithScopedProxy() {
RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
rbd.setResource(new DescriptiveResource("XML or something"));
- BeanDefinitionHolder proxied = ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(rbd, "bar"),
- beanFactory, true);
+ BeanDefinitionHolder proxied = ScopedProxyUtils.createScopedProxy(
+ new BeanDefinitionHolder(rbd, "bar"), beanFactory, true);
beanFactory.registerBeanDefinition("bar", proxied.getBeanDefinition());
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
@@ -296,8 +296,7 @@ public class ConfigurationClassPostProcessorTests {
RootBeanDefinition bd = new RootBeanDefinition(RepositoryInjectionBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
beanFactory.registerBeanDefinition("annotatedBean", bd);
- beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(
- ScopedProxyRepositoryConfiguration.class));
+ beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(ScopedProxyRepositoryConfiguration.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
beanFactory.freezeConfiguration();
@@ -332,8 +331,7 @@ public class ConfigurationClassPostProcessorTests {
RootBeanDefinition bd = new RootBeanDefinition(RepositoryFactoryBeanInjectionBean.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
beanFactory.registerBeanDefinition("annotatedBean", bd);
- beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(
- RepositoryFactoryBeanConfiguration.class));
+ beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(RepositoryFactoryBeanConfiguration.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
beanFactory.preInstantiateSingletons();
@@ -374,8 +372,7 @@ public class ConfigurationClassPostProcessorTests {
@Test
public void genericsBasedInjectionWithWildcardWithGenericExtendsMatch() {
- beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(
- WildcardWithGenericExtendsConfiguration.class));
+ beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(WildcardWithGenericExtendsConfiguration.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
@@ -574,7 +571,6 @@ public class ConfigurationClassPostProcessorTests {
@Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Repository This implementation checks for the presence of the given name within
- * the {@link #getPropertyNames()} array.
- * @param name the property to find
+ * This implementation checks for the presence of the given name within the
+ * {@link #getPropertyNames()} array.
+ * @param name the name of the property to find
*/
@Override
public boolean containsProperty(String name) {
- Assert.notNull(name, "property name must not be null");
- for (String candidate : this.getPropertyNames()) {
+ Assert.notNull(name, "Property name must not be null");
+ for (String candidate : getPropertyNames()) {
if (candidate.equals(name)) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("PropertySource [%s] contains '%s'", getName(), name));
diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java
index aab278b895b..aa05d047fc6 100644
--- a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java
+++ b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2014 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.
@@ -18,7 +18,9 @@ package org.springframework.core.env;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.util.Assert;
+import org.springframework.util.ObjectUtils;
/**
* Abstract base class representing a source of name/value property pairs. The underlying
@@ -55,12 +57,13 @@ import org.springframework.util.Assert;
*/
public abstract class PropertySource No properties other than {@code name} are evaluated.
+ * No properties other than {@code name} are evaluated.
*/
@Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof PropertySource))
- return false;
- PropertySource> other = (PropertySource>) obj;
- if (this.name == null) {
- if (other.name != null)
- return false;
- } else if (!this.name.equals(other.name))
- return false;
- return true;
+ return (this == obj || (obj instanceof PropertySource &&
+ ObjectUtils.nullSafeEquals(this.name, ((PropertySource>) obj).name)));
+ }
+
+ /**
+ * Return a hash code derived from the {@code name} property
+ * of this {@code PropertySource} object.
+ */
+ @Override
+ public int hashCode() {
+ return ObjectUtils.nullSafeHashCode(this.name);
}
/**
* Produce concise output (type and name) if the current log level does not include
- * debug. If debug is enabled, produce verbose output including hashcode of the
+ * debug. If debug is enabled, produce verbose output including hash code of the
* PropertySource instance and every name/value property pair.
- *
- * This variable verbosity is useful as a property source such as system properties
+ * This variable verbosity is useful as a property source such as system properties
* or environment variables may contain an arbitrary number of property pairs,
* potentially leading to difficult to read exception and log messages.
- *
* @see Log#isDebugEnabled()
*/
@Override
public String toString() {
if (logger.isDebugEnabled()) {
return String.format("%s@%s [name='%s', properties=%s]",
- this.getClass().getSimpleName(), System.identityHashCode(this), this.name, this.source);
+ getClass().getSimpleName(), System.identityHashCode(this), this.name, this.source);
+ }
+ else {
+ return String.format("%s [name='%s']", getClass().getSimpleName(), this.name);
}
-
- return String.format("%s [name='%s']",
- this.getClass().getSimpleName(), this.name);
}
/**
* Return a {@code PropertySource} implementation intended for collection comparison purposes only.
- *
* Primarily for internal use, but given a collection of {@code PropertySource} objects, may be
* used as follows:
*
- *
- *
- *
@@ -189,11 +177,9 @@ public abstract class PropertySource
- *
* The returned {@code PropertySource} will throw {@code UnsupportedOperationException}
* if any methods other than {@code equals(Object)}, {@code hashCode()}, and {@code toString()}
* are called.
- *
* @param name the name of the comparison {@code PropertySource} to be created and returned.
*/
public static PropertySource> named(String name) {
@@ -209,7 +195,6 @@ public abstract class PropertySource