diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java
index 83230f7461..e88a4d3b72 100644
--- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java
+++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java
@@ -125,8 +125,10 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
Executor executorToUse = this.defaultExecutor;
String qualifier = getExecutorQualifier(method);
if (StringUtils.hasLength(qualifier)) {
- Assert.notNull(this.beanFactory, "BeanFactory must be set on " + getClass().getSimpleName() +
- " to access qualified executor '" + qualifier + "'");
+ if (this.beanFactory == null) {
+ throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
+ " to access qualified executor '" + qualifier + "'");
+ }
executorToUse = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
this.beanFactory, Executor.class, qualifier);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
index ff8eac4403..0f950b8a25 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -679,7 +679,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
if (Modifier.isStatic(factoryMethod.getModifiers()) == isStatic &&
factoryMethod.getName().equals(mbd.getFactoryMethodName()) &&
factoryMethod.getParameterTypes().length >= minNrOfArgs) {
- // No declared type variables to inspect, so just process the standard return type.
+ // Declared type variables to inspect?
if (factoryMethod.getTypeParameters().length > 0) {
try {
// Fully resolve parameter names and argument values.
@@ -833,8 +833,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
/**
* Obtain a "shortcut" singleton FactoryBean instance to use for a
- * {@code getObjectType()} call, without full initialization
- * of the FactoryBean.
+ * {@code getObjectType()} call, without full initialization of the FactoryBean.
* @param beanName the name of the bean
* @param mbd the bean definition for the bean
* @return the FactoryBean instance, or {@code null} to indicate
@@ -875,8 +874,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
/**
* Obtain a "shortcut" non-singleton FactoryBean instance to use for a
- * {@code getObjectType()} call, without full initialization
- * of the FactoryBean.
+ * {@code getObjectType()} call, without full initialization of the FactoryBean.
* @param beanName the name of the bean
* @param mbd the bean definition for the bean
* @return the FactoryBean instance, or {@code null} to indicate
diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationScopeMetadataResolver.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationScopeMetadataResolver.java
index 5d4ce9c952..08220e9b74 100644
--- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationScopeMetadataResolver.java
+++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationScopeMetadataResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -25,10 +25,10 @@ import org.springframework.util.Assert;
/**
* A {@link ScopeMetadataResolver} implementation that by default checks for
- * the presence of Spring's {@link Scope} annotation on the bean class.
+ * the presence of Spring's {@link Scope @Scope} annotation on the bean class.
*
- *
The exact type of annotation that is checked for is configurable via the
- * {@link #setScopeAnnotationType(Class)} property.
+ *
The exact type of annotation that is checked for is configurable via
+ * {@link #setScopeAnnotationType(Class)}.
*
* @author Mark Fisher
* @author Juergen Hoeller
@@ -43,7 +43,7 @@ public class AnnotationScopeMetadataResolver implements ScopeMetadataResolver {
/**
- * Create a new instance of the {@code AnnotationScopeMetadataResolver} class.
+ * Construct a new {@code AnnotationScopeMetadataResolver}.
* @see #AnnotationScopeMetadataResolver(ScopedProxyMode)
* @see ScopedProxyMode#NO
*/
@@ -52,8 +52,9 @@ public class AnnotationScopeMetadataResolver implements ScopeMetadataResolver {
}
/**
- * Create a new instance of the {@code AnnotationScopeMetadataResolver} class.
- * @param defaultProxyMode the desired scoped-proxy mode
+ * Construct a new {@code AnnotationScopeMetadataResolver} using the
+ * supplied default {@link ScopedProxyMode}.
+ * @param defaultProxyMode the default scoped-proxy mode
*/
public AnnotationScopeMetadataResolver(ScopedProxyMode defaultProxyMode) {
Assert.notNull(defaultProxyMode, "'defaultProxyMode' must not be null");
@@ -63,7 +64,7 @@ public class AnnotationScopeMetadataResolver implements ScopeMetadataResolver {
/**
* Set the type of annotation that is checked for by this
- * {@link AnnotationScopeMetadataResolver}.
+ * {@code AnnotationScopeMetadataResolver}.
* @param scopeAnnotationType the target annotation type
*/
public void setScopeAnnotationType(Class extends Annotation> scopeAnnotationType) {
diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableAsync.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableAsync.java
index e02ce9dd5c..9c9f439732 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableAsync.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableAsync.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -138,11 +138,11 @@ import org.springframework.core.Ordered;
public @interface EnableAsync {
/**
- * Indicate the 'async' annotation type to be detected at either class
- * or method level. By default, both the {@link Async} annotation and
- * the EJB 3.1 {@code javax.ejb.Asynchronous} annotation will be
- * detected.
This setter property exists so that developers can provide
- * their own (non-Spring-specific) annotation type to indicate that a method
+ * Indicate the 'async' annotation type to be detected at either class or
+ * method level. By default, both the {@link Async} annotation and the
+ * EJB 3.1 {@code javax.ejb.Asynchronous} annotation will be detected.
+ *
This setter property exists so that developers can provide their
+ * own (non-Spring-specific) annotation type to indicate that a method
* (or all methods of a given class) should be invoked asynchronously.
*/
Class extends Annotation> annotation() default Annotation.class;
@@ -151,7 +151,6 @@ public @interface EnableAsync {
* Indicate whether subclass-based (CGLIB) proxies are to be created as opposed
* to standard Java interface-based proxies. The default is {@code false}.
* Applicable only if {@link #mode()} is set to {@link AdviceMode#PROXY}.
- *
*
Note that setting this attribute to {@code true} will affect all
* Spring-managed beans requiring proxying, not just those marked with {@code @Async}.
* For example, other beans marked with Spring's {@code @Transactional} annotation
@@ -176,4 +175,5 @@ public @interface EnableAsync {
* existing proxies rather than double-proxy.
*/
int order() default Ordered.LOWEST_PRECEDENCE;
+
}
diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
index 28db2a3a11..bdc33c4a8d 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -23,13 +23,12 @@ import org.springframework.context.annotation.Role;
import org.springframework.scheduling.config.TaskManagementConfigUtils;
/**
- * {@code @Configuration} class that registers a {@link
- * ScheduledAnnotationBeanPostProcessor} bean capable of processing Spring's @{@link
- * Scheduled} annotation.
+ * {@code @Configuration} class that registers a {@link ScheduledAnnotationBeanPostProcessor}
+ * bean capable of processing Spring's @{@link Scheduled} annotation.
*
- *
This configuration class is automatically imported when using the @{@link
- * EnableScheduling} annotation. See {@code @EnableScheduling} Javadoc for complete usage
- * details.
+ *
This configuration class is automatically imported when using the
+ * @{@link EnableScheduling} annotation. See {@code @EnableScheduling}'s javadoc
+ * for complete usage details.
*
* @author Chris Beams
* @since 3.1
diff --git a/spring-context/src/main/java/org/springframework/validation/DataBinder.java b/spring-context/src/main/java/org/springframework/validation/DataBinder.java
index 73b1753836..1e1172d792 100644
--- a/spring-context/src/main/java/org/springframework/validation/DataBinder.java
+++ b/spring-context/src/main/java/org/springframework/validation/DataBinder.java
@@ -543,7 +543,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
* Return the primary Validator to apply after each binding step, if any.
*/
public Validator getValidator() {
- return this.validators.size() > 0 ? this.validators.get(0) : null;
+ return (this.validators.size() > 0 ? this.validators.get(0) : null);
}
/**
diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
index b3881e0793..ed7ea99fef 100644
--- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
+++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -67,17 +67,6 @@ public class EnableAsyncTests {
asyncBean.work();
}
-
- @Configuration
- @EnableAsync
- static class AsyncConfig {
- @Bean
- public AsyncBean asyncBean() {
- return new AsyncBean();
- }
- }
-
-
@Test
public void withAsyncBeanWithExecutorQualifiedByName() throws ExecutionException, InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -95,49 +84,6 @@ public class EnableAsyncTests {
assertThat(workerThread3.get().getName(), startsWith("otherExecutor-"));
}
-
- static class AsyncBeanWithExecutorQualifiedByName {
- @Async
- public Future work0() {
- return new AsyncResult(Thread.currentThread());
- }
-
- @Async("e1")
- public Future work() {
- return new AsyncResult(Thread.currentThread());
- }
-
- @Async("otherExecutor")
- public Future work2() {
- return new AsyncResult(Thread.currentThread());
- }
-
- @Async("e2")
- public Future work3() {
- return new AsyncResult(Thread.currentThread());
- }
- }
-
-
- static class AsyncBean {
- private Thread threadOfExecution;
-
- @Async
- public void work() {
- this.threadOfExecution = Thread.currentThread();
- }
-
- @Async
- public void fail() {
- throw new UnsupportedOperationException();
- }
-
- public Thread getThreadOfExecution() {
- return threadOfExecution;
- }
- }
-
-
@Test
public void asyncProcessorIsOrderedLowestPrecedenceByDefault() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -148,7 +94,6 @@ public class EnableAsyncTests {
assertThat(bpp.getOrder(), is(Ordered.LOWEST_PRECEDENCE));
}
-
@Test
public void orderAttributeIsPropagated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -159,17 +104,6 @@ public class EnableAsyncTests {
assertThat(bpp.getOrder(), is(Ordered.HIGHEST_PRECEDENCE));
}
-
- @Configuration
- @EnableAsync(order=Ordered.HIGHEST_PRECEDENCE)
- static class OrderedAsyncConfig {
- @Bean
- public AsyncBean asyncBean() {
- return new AsyncBean();
- }
- }
-
-
@Test
public void customAsyncAnnotationIsPropagated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -188,51 +122,16 @@ public class EnableAsyncTests {
assertTrue("bean was not async advised as expected", isAsyncAdvised);
}
-
- @Configuration
- @EnableAsync(annotation=CustomAsync.class)
- static class CustomAsyncAnnotationConfig {
- @Bean
- public CustomAsyncBean asyncBean() {
- return new CustomAsyncBean();
- }
- }
-
-
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- @interface CustomAsync {
- }
-
-
- static class CustomAsyncBean {
- @CustomAsync
- public void work() {
- }
- }
-
-
/**
* Fails with classpath errors on trying to classload AnnotationAsyncExecutionAspect
*/
- @Test(expected=BeanDefinitionStoreException.class)
+ @Test(expected = BeanDefinitionStoreException.class)
public void aspectModeAspectJAttemptsToRegisterAsyncAspect() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AspectJAsyncAnnotationConfig.class);
ctx.refresh();
}
-
- @Configuration
- @EnableAsync(mode=AdviceMode.ASPECTJ)
- static class AspectJAsyncAnnotationConfig {
- @Bean
- public AsyncBean asyncBean() {
- return new AsyncBean();
- }
- }
-
-
@Test
public void customExecutorIsPropagated() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -257,9 +156,112 @@ public class EnableAsyncTests {
}
+ static class AsyncBeanWithExecutorQualifiedByName {
+
+ @Async
+ public Future work0() {
+ return new AsyncResult(Thread.currentThread());
+ }
+
+ @Async("e1")
+ public Future work() {
+ return new AsyncResult(Thread.currentThread());
+ }
+
+ @Async("otherExecutor")
+ public Future work2() {
+ return new AsyncResult(Thread.currentThread());
+ }
+
+ @Async("e2")
+ public Future work3() {
+ return new AsyncResult(Thread.currentThread());
+ }
+ }
+
+
+ static class AsyncBean {
+
+ private Thread threadOfExecution;
+
+ @Async
+ public void work() {
+ this.threadOfExecution = Thread.currentThread();
+ }
+
+ @Async
+ public void fail() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Thread getThreadOfExecution() {
+ return threadOfExecution;
+ }
+ }
+
+
+ @Configuration
+ @EnableAsync(annotation = CustomAsync.class)
+ static class CustomAsyncAnnotationConfig {
+
+ @Bean
+ public CustomAsyncBean asyncBean() {
+ return new CustomAsyncBean();
+ }
+ }
+
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ @interface CustomAsync {
+ }
+
+
+ static class CustomAsyncBean {
+
+ @CustomAsync
+ public void work() {
+ }
+ }
+
+
+ @Configuration
+ @EnableAsync(order = Ordered.HIGHEST_PRECEDENCE)
+ static class OrderedAsyncConfig {
+
+ @Bean
+ public AsyncBean asyncBean() {
+ return new AsyncBean();
+ }
+ }
+
+
+ @Configuration
+ @EnableAsync(mode = AdviceMode.ASPECTJ)
+ static class AspectJAsyncAnnotationConfig {
+
+ @Bean
+ public AsyncBean asyncBean() {
+ return new AsyncBean();
+ }
+ }
+
+
+ @Configuration
+ @EnableAsync
+ static class AsyncConfig {
+
+ @Bean
+ public AsyncBean asyncBean() {
+ return new AsyncBean();
+ }
+ }
+
+
@Configuration
@EnableAsync
static class CustomExecutorAsyncConfig implements AsyncConfigurer {
+
@Bean
public AsyncBean asyncBean() {
return new AsyncBean();
@@ -275,7 +277,7 @@ public class EnableAsyncTests {
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
- return exceptionHandler();
+ return exceptionHandler();
}
@Bean
@@ -288,6 +290,7 @@ public class EnableAsyncTests {
@Configuration
@EnableAsync
static class AsyncWithExecutorQualifiedByNameConfig {
+
@Bean
public AsyncBeanWithExecutorQualifiedByName asyncBean() {
return new AsyncBeanWithExecutorQualifiedByName();
@@ -295,15 +298,14 @@ public class EnableAsyncTests {
@Bean
public Executor e1() {
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
- return executor;
+ return new ThreadPoolTaskExecutor();
}
@Bean
@Qualifier("e2")
public Executor otherExecutor() {
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
- return executor;
+ return new ThreadPoolTaskExecutor();
}
}
+
}
diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java
index 646f1cd366..3d866de05f 100644
--- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java
+++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -41,6 +41,7 @@ import static org.junit.Assert.*;
* Tests use of @EnableScheduling on @Configuration classes.
*
* @author Chris Beams
+ * @author Sam Brannen
* @since 3.1
*/
public class EnableSchedulingTests {
@@ -50,6 +51,7 @@ public class EnableSchedulingTests {
Assume.group(TestGroup.PERFORMANCE);
}
+
@Test
public void withFixedRateTask() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -138,12 +140,17 @@ public class EnableSchedulingTests {
ctx.register(AmbiguousExplicitSchedulerConfig.class);
try {
ctx.refresh();
- } catch (IllegalStateException ex) {
+ }
+ catch (IllegalStateException ex) {
assertThat(ex.getMessage(), startsWith("More than one TaskScheduler"));
throw ex;
}
+ finally {
+ ctx.close();
+ }
}
+
@EnableScheduling @Configuration
static class AmbiguousExplicitSchedulerConfig {
@@ -236,6 +243,7 @@ public class EnableSchedulingTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(SchedulingEnabled_withAmbiguousTaskSchedulers_butNoActualTasks.class);
ctx.refresh();
+ ctx.close();
}
@@ -265,10 +273,14 @@ public class EnableSchedulingTests {
ctx.register(SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask.class);
try {
ctx.refresh();
- } catch (IllegalStateException ex) {
- assertThat(ex.getMessage(), startsWith("More than one TaskScheduler and/or"));
+ }
+ catch (IllegalStateException ex) {
+ assertThat(ex.getMessage(), startsWith("More than one TaskScheduler"));
throw ex;
}
+ finally {
+ ctx.close();
+ }
}
@@ -295,6 +307,7 @@ public class EnableSchedulingTests {
}
}
+
@Test
public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrarBean() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -476,6 +489,7 @@ public class EnableSchedulingTests {
}
}
+
@Test
public void withInitiallyDelayedFixedRateTask() throws InterruptedException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -486,8 +500,8 @@ public class EnableSchedulingTests {
AtomicInteger counter = ctx.getBean(AtomicInteger.class);
ctx.close();
- assertThat(counter.get(), greaterThan(0)); // the @Scheduled method was called
- assertThat(counter.get(), lessThanOrEqualTo(10)); // but not more than times the delay allows
+ assertThat(counter.get(), greaterThan(0)); // the @Scheduled method was called
+ assertThat(counter.get(), lessThanOrEqualTo(10)); // but not more than times the delay allows
}
diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java
index ef43b7d7f2..831191cfb2 100644
--- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java
+++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java
@@ -30,8 +30,9 @@ import org.springframework.util.Assert;
/**
* Helper class that encapsulates the specification of a method parameter, i.e.
- * a Method or Constructor plus a parameter index and a nested type index for
- * a declared generic type. Useful as a specification object to pass along.
+ * a {@link Method} or {@link Constructor} plus a parameter index and a nested
+ * type index for a declared generic type. Useful as a specification object to
+ * pass along.
*
* @author Juergen Hoeller
* @author Rob Harrop
@@ -66,20 +67,22 @@ public class MethodParameter {
/**
- * Create a new MethodParameter for the given method, with nesting level 1.
+ * Create a new {@code MethodParameter} for the given method, with nesting level 1.
* @param method the Method to specify a parameter for
- * @param parameterIndex the index of the parameter
+ * @param parameterIndex the index of the parameter: -1 for the method
+ * return type; 0 for the first method parameter; 1 for the second method
+ * parameter, etc.
*/
public MethodParameter(Method method, int parameterIndex) {
this(method, parameterIndex, 1);
}
/**
- * Create a new MethodParameter for the given method.
+ * Create a new {@code MethodParameter} for the given method.
* @param method the Method to specify a parameter for
- * @param parameterIndex the index of the parameter
- * (-1 for the method return type; 0 for the first method parameter,
- * 1 for the second method parameter, etc)
+ * @param parameterIndex the index of the parameter: -1 for the method
+ * return type; 0 for the first method parameter; 1 for the second method
+ * parameter, etc.
* @param nestingLevel the nesting level of the target type
* (typically 1; e.g. in case of a List of Lists, 1 would indicate the
* nested List, whereas 2 would indicate the element of the nested List)
@@ -197,7 +200,7 @@ public class MethodParameter {
/**
* Return the index of the method/constructor parameter.
- * @return the parameter index (never negative)
+ * @return the parameter index (-1 in case of the return type)
*/
public int getParameterIndex() {
return this.parameterIndex;
diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
index 2adbae874f..6e3e227704 100644
--- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
+++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
@@ -129,6 +129,7 @@ public class AntPathMatcher implements PathMatcher {
* turn it off when encountering too many patterns to cache at runtime
* (the threshold is 65536), assuming that arbitrary permutations of patterns
* are coming in, with little chance for encountering a recurring pattern.
+ * @since 4.0.1
* @see #getStringMatcher(String)
*/
public void setCachePatterns(boolean cachePatterns) {
@@ -413,18 +414,18 @@ public class AntPathMatcher implements PathMatcher {
public Map extractUriTemplateVariables(String pattern, String path) {
Map variables = new LinkedHashMap();
boolean result = doMatch(pattern, path, true, variables);
- Assert.state(result, "Pattern \"" + pattern + "\" is not a match for \"" + path + "\"");
+ if (!result) {
+ throw new IllegalStateException("Pattern \"" + pattern + "\" is not a match for \"" + path + "\"");
+ }
return variables;
}
/**
* Combine two patterns into a new pattern.
- *
* This implementation simply concatenates the two patterns, unless
* the first pattern contains a file extension match (e.g., {@code *.html}).
* In that case, the second pattern will be merged into the first. Otherwise,
* an {@code IllegalArgumentException} will be thrown.
- *
*
Examples
*
* | Pattern 1 | Pattern 2 | Result |
@@ -442,7 +443,6 @@ public class AntPathMatcher implements PathMatcher {
* | /*.html | /hotels | /hotels.html |
* | /*.html | /*.txt | {@code IllegalArgumentException} |
*
- *
* @param pattern1 the first pattern
* @param pattern2 the second pattern
* @return the combination of the two patterns
@@ -484,6 +484,7 @@ public class AntPathMatcher implements PathMatcher {
// simply concatenate the two patterns
return concat(pattern1, pattern2);
}
+
String extension1 = pattern1.substring(starDotPos1 + 1);
int dotPos2 = pattern2.indexOf('.');
String fileName2 = (dotPos2 == -1 ? pattern2 : pattern2.substring(0, dotPos2));
@@ -508,14 +509,18 @@ public class AntPathMatcher implements PathMatcher {
}
/**
- * Given a full path, returns a {@link Comparator} suitable for sorting patterns in order of explicitness.
- * The returned {@code Comparator} will {@linkplain java.util.Collections#sort(java.util.List,
- * java.util.Comparator) sort} a list so that more specific patterns (without uri templates or wild cards) come before
- * generic patterns. So given a list with the following patterns:
- {@code /hotels/new}
- * - {@code /hotels/{hotel}}
- {@code /hotels/*}
the returned comparator will sort this
- * list so that the order will be as indicated.
- * The full path given as parameter is used to test for exact matches. So when the given path is {@code /hotels/2},
- * the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
+ * Given a full path, returns a {@link Comparator} suitable for sorting patterns in order of
+ * explicitness.
+ *
This{@code Comparator} will {@linkplain java.util.Collections#sort(List, Comparator) sort}
+ * a list so that more specific patterns (without uri templates or wild cards) come before
+ * generic patterns. So given a list with the following patterns:
+ *
+ * - {@code /hotels/new}
+ * - {@code /hotels/{hotel}}
- {@code /hotels/*}
+ *
+ * the returned comparator will sort this list so that the order will be as indicated.
+ * The full path given as parameter is used to test for exact matches. So when the given path
+ * is {@code /hotels/2}, the pattern {@code /hotels/2} will be sorted before {@code /hotels/1}.
* @param path the full path to use for comparison
* @return a comparator capable of sorting patterns in order of explicitness
*/
@@ -542,11 +547,11 @@ public class AntPathMatcher implements PathMatcher {
public AntPathStringMatcher(String pattern) {
StringBuilder patternBuilder = new StringBuilder();
- Matcher m = GLOB_PATTERN.matcher(pattern);
+ Matcher matcher = GLOB_PATTERN.matcher(pattern);
int end = 0;
- while (m.find()) {
- patternBuilder.append(quote(pattern, end, m.start()));
- String match = m.group();
+ while (matcher.find()) {
+ patternBuilder.append(quote(pattern, end, matcher.start()));
+ String match = matcher.group();
if ("?".equals(match)) {
patternBuilder.append('.');
}
@@ -557,7 +562,7 @@ public class AntPathMatcher implements PathMatcher {
int colonIdx = match.indexOf(':');
if (colonIdx == -1) {
patternBuilder.append(DEFAULT_VARIABLE_PATTERN);
- this.variableNames.add(m.group(1));
+ this.variableNames.add(matcher.group(1));
}
else {
String variablePattern = match.substring(colonIdx + 1, match.length() - 1);
@@ -568,7 +573,7 @@ public class AntPathMatcher implements PathMatcher {
this.variableNames.add(variableName);
}
}
- end = m.end();
+ end = matcher.end();
}
patternBuilder.append(quote(pattern, end, pattern.length()));
this.pattern = Pattern.compile(patternBuilder.toString());
@@ -590,10 +595,12 @@ public class AntPathMatcher implements PathMatcher {
if (matcher.matches()) {
if (uriTemplateVariables != null) {
// SPR-8455
- Assert.isTrue(this.variableNames.size() == matcher.groupCount(),
- "The number of capturing groups in the pattern segment " + this.pattern +
- " does not match the number of URI template variables it defines, which can occur if " +
- " capturing groups are used in a URI template regex. Use non-capturing groups instead.");
+ if (this.variableNames.size() != matcher.groupCount()) {
+ throw new IllegalArgumentException("The number of capturing groups in the pattern segment " +
+ this.pattern + " does not match the number of URI template variables it defines, " +
+ "which can occur if capturing groups are used in a URI template regex. " +
+ "Use non-capturing groups instead.");
+ }
for (int i = 1; i <= matcher.groupCount(); i++) {
String name = this.variableNames.get(i - 1);
String value = matcher.group(i);
diff --git a/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java b/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java
index edebcb5949..767f5cee3b 100644
--- a/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java
+++ b/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -17,7 +17,7 @@
package org.springframework.expression;
/**
- * Super class for exceptions that can occur whilst processing expressions
+ * Super class for exceptions that can occur whilst processing expressions.
*
* @author Andy Clement
* @since 3.0
@@ -27,11 +27,11 @@ public class ExpressionException extends RuntimeException {
protected String expressionString;
- protected int position; // -1 if not known - but should be known in all reasonable cases
+ protected int position; // -1 if not known - but should be known in all reasonable cases
/**
- * Creates a new expression exception.
+ * Construct a new expression exception.
* @param expressionString the expression string
* @param message a descriptive message
*/
@@ -42,7 +42,7 @@ public class ExpressionException extends RuntimeException {
}
/**
- * Creates a new expression exception.
+ * Construct a new expression exception.
* @param expressionString the expression string
* @param position the position in the expression string where the problem occurred
* @param message a descriptive message
@@ -54,7 +54,7 @@ public class ExpressionException extends RuntimeException {
}
/**
- * Creates a new expression exception.
+ * Construct a new expression exception.
* @param position the position in the expression string where the problem occurred
* @param message a descriptive message
*/
@@ -64,7 +64,7 @@ public class ExpressionException extends RuntimeException {
}
/**
- * Creates a new expression exception.
+ * Construct a new expression exception.
* @param position the position in the expression string where the problem occurred
* @param message a descriptive message
* @param cause the underlying cause of this exception
@@ -75,21 +75,40 @@ public class ExpressionException extends RuntimeException {
}
/**
- * Creates a new expression exception.
+ * Construct a new expression exception.
* @param message a descriptive message
*/
public ExpressionException(String message) {
super(message);
}
+ /**
+ * Construct a new expression exception.
+ * @param message a descriptive message
+ * @param cause the underlying cause of this exception
+ */
public ExpressionException(String message, Throwable cause) {
super(message,cause);
}
/**
- * Return the exception message. Since Spring 4.0 this method returns the same
- * result as {@link #toDetailedString()}.
+ * Return the expression string.
+ */
+ public final String getExpressionString() {
+ return this.expressionString;
+ }
+
+ /**
+ * Return the position in the expression string where the problem occurred.
+ */
+ public final int getPosition() {
+ return this.position;
+ }
+
+ /**
+ * Return the exception message. Since Spring 4.0 this method returns the
+ * same result as {@link #toDetailedString()}.
* @see java.lang.Throwable#getMessage()
*/
@Override
@@ -98,35 +117,34 @@ public class ExpressionException extends RuntimeException {
}
/**
- * Return the exception simple message without including the expression that caused
- * the failure.
+ * Return a detailed description of this exception, including the expression
+ * String and position (if available) as well as the actual exception message.
+ */
+ public String toDetailedString() {
+ if (this.expressionString != null) {
+ StringBuilder output = new StringBuilder();
+ output.append("Expression '");
+ output.append(this.expressionString);
+ output.append("'");
+ if (this.position != -1) {
+ output.append(" @ ");
+ output.append(this.position);
+ }
+ output.append(": ");
+ output.append(getSimpleMessage());
+ return output.toString();
+ }
+ else {
+ return getSimpleMessage();
+ }
+ }
+
+ /**
+ * Return the exception simple message without including the expression
+ * that caused the failure.
*/
public String getSimpleMessage() {
return super.getMessage();
}
- public String toDetailedString() {
- StringBuilder output = new StringBuilder();
- if (this.expressionString!=null) {
- output.append("Expression '");
- output.append(this.expressionString);
- output.append("'");
- if (this.position!=-1) {
- output.append(" @ ");
- output.append(this.position);
- }
- output.append(": ");
- }
- output.append(getSimpleMessage());
- return output.toString();
- }
-
- public final String getExpressionString() {
- return this.expressionString;
- }
-
- public final int getPosition() {
- return this.position;
- }
-
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java b/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
index 2044e9e756..5b91d9ae25 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -56,7 +56,7 @@ public class CodeFlow implements Opcodes {
* will be called after the main evaluation function has finished being generated.
*/
private List fieldAdders = null;
-
+
/**
* As SpEL ast nodes are called to generate code for the main evaluation method
* they can register to add code to a static initializer in the class. Any
@@ -64,19 +64,19 @@ public class CodeFlow implements Opcodes {
* has finished being generated.
*/
private List clinitAdders = null;
-
+
/**
* Name of the class being generated. Typically used when generating code
* that accesses freshly generated fields on the generated type.
*/
private String clazzName;
-
+
/**
* When code generation requires holding a value in a class level field, this
* is used to track the next available field id (used as a name suffix).
*/
private int nextFieldId = 1;
-
+
/**
* When code generation requires an intermediate variable within a method,
* this method records the next available variable (variable 0 is 'this').
@@ -211,7 +211,7 @@ public class CodeFlow implements Opcodes {
/**
* Create the JVM signature descriptor for a method. This consists of the descriptors
- * for the constructor parameters surrounded with parentheses, followed by the
+ * for the method parameters surrounded with parentheses, followed by the
* descriptor for the return type. Note the descriptors here are JVM descriptors,
* unlike the other descriptor forms the compiler is using which do not include the
* trailing semicolon.
@@ -232,11 +232,12 @@ public class CodeFlow implements Opcodes {
/**
* Create the JVM signature descriptor for a constructor. This consists of the
- * descriptors for the constructor parameters surrounded with parentheses. Note the
+ * descriptors for the constructor parameters surrounded with parentheses, followed by
+ * the descriptor for the return type, which is always "V". Note the
* descriptors here are JVM descriptors, unlike the other descriptor forms the
* compiler is using which do not include the trailing semicolon.
* @param ctor the constructor
- * @return a String signature descriptor (e.g. "(ILjava/lang/String;)")
+ * @return a String signature descriptor (e.g. "(ILjava/lang/String;)V")
*/
public static String createSignatureDescriptor(Constructor> ctor) {
Class>[] params = ctor.getParameterTypes();
@@ -657,7 +658,7 @@ public class CodeFlow implements Opcodes {
}
return descriptors;
}
-
+
/**
* Called after the main expression evaluation method has been generated, this
* method will callback any registered FieldAdders or ClinitAdders to add any
@@ -695,7 +696,7 @@ public class CodeFlow implements Opcodes {
}
/**
- * Register a ClinitAdder which will add code to the static
+ * Register a ClinitAdder which will add code to the static
* initializer in the generated class to support the code
* produced by an ast nodes primary generateCode() method.
*/
@@ -717,11 +718,11 @@ public class CodeFlow implements Opcodes {
public String getClassname() {
return clazzName;
}
-
+
public interface FieldAdder {
public void generateField(ClassWriter cw, CodeFlow codeflow);
}
-
+
public interface ClinitAdder {
public void generateCode(MethodVisitor mv, CodeFlow codeflow);
}
@@ -743,11 +744,11 @@ public class CodeFlow implements Opcodes {
}
else {
mv.visitLdcInsn(value);
- }
+ }
}
/**
- * Produce appropriate bytecode to store a stack item in an array. The
+ * Produce appropriate bytecode to store a stack item in an array. The
* instruction to use varies depending on whether the type
* is a primitive or reference type.
* @param mv where to insert the bytecode
@@ -781,7 +782,7 @@ public class CodeFlow implements Opcodes {
public static int arrayCodeFor(String arraytype) {
switch (arraytype.charAt(0)) {
case 'I': return T_INT;
- case 'J': return T_LONG;
+ case 'J': return T_LONG;
case 'F': return T_FLOAT;
case 'D': return T_DOUBLE;
case 'B': return T_BYTE;
@@ -805,9 +806,9 @@ public class CodeFlow implements Opcodes {
}
return false;
}
-
+
/**
- * Produce the correct bytecode to build an array. The opcode to use and the
+ * Produce the correct bytecode to build an array. The opcode to use and the
* signature to pass along with the opcode can vary depending on the signature
* of the array type.
* @param mv the methodvisitor into which code should be inserted
@@ -825,7 +826,8 @@ public class CodeFlow implements Opcodes {
// is [[I then we want [I and not [I;
if (CodeFlow.isReferenceTypeArray(arraytype)) {
mv.visitTypeInsn(ANEWARRAY, arraytype+";");
- } else {
+ }
+ else {
mv.visitTypeInsn(ANEWARRAY, arraytype);
}
}
@@ -835,5 +837,4 @@ public class CodeFlow implements Opcodes {
}
}
-
}
diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/config/InitializeDatabaseIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/config/InitializeDatabaseIntegrationTests.java
index 286a897f2e..723707add1 100644
--- a/spring-jdbc/src/test/java/org/springframework/jdbc/config/InitializeDatabaseIntegrationTests.java
+++ b/spring-jdbc/src/test/java/org/springframework/jdbc/config/InitializeDatabaseIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 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.
@@ -37,8 +37,10 @@ import static org.junit.Assert.*;
public class InitializeDatabaseIntegrationTests {
private String enabled;
+
private ClassPathXmlApplicationContext context;
+
@Before
public void init() {
enabled = System.setProperty("ENABLED", "true");
@@ -48,7 +50,8 @@ public class InitializeDatabaseIntegrationTests {
public void after() {
if (enabled != null) {
System.setProperty("ENABLED", enabled);
- } else {
+ }
+ else {
System.clearProperty("ENABLED");
}
if (context != null) {
@@ -56,6 +59,7 @@ public class InitializeDatabaseIntegrationTests {
}
}
+
@Test
public void testCreateEmbeddedDatabase() throws Exception {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-config.xml");
@@ -107,13 +111,15 @@ public class InitializeDatabaseIntegrationTests {
}
private void assertCorrectSetup(DataSource dataSource) {
- JdbcTemplate t = new JdbcTemplate(dataSource);
- assertEquals(1, t.queryForObject("select count(*) from T_TEST", Integer.class).intValue());
+ JdbcTemplate jt = new JdbcTemplate(dataSource);
+ assertEquals(1, jt.queryForObject("select count(*) from T_TEST", Integer.class).intValue());
}
+
public static class CacheData implements InitializingBean {
private JdbcTemplate jdbcTemplate;
+
private List