diff --git a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java b/spring-aop/src/main/java/org/springframework/aop/TargetSource.java
index 8e5ccc1fa6c..f23e16f38db 100644
--- a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/TargetSource.java
@@ -1,5 +1,5 @@
/*<
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -34,9 +34,8 @@ public interface TargetSource extends TargetClassAware {
/**
* Return the type of targets returned by this {@link TargetSource}.
- *
Can return {@code null}, although certain usages of a
- * {@code TargetSource} might just work with a predetermined
- * target class.
+ *
Can return {@code null}, although certain usages of a {@code TargetSource}
+ * might just work with a predetermined target class.
* @return the type of targets returned by this {@link TargetSource}
*/
@Override
@@ -44,9 +43,8 @@ public interface TargetSource extends TargetClassAware {
/**
* Will all calls to {@link #getTarget()} return the same object?
- *
In that case, there will be no need to invoke
- * {@link #releaseTarget(Object)}, and the AOP framework can cache
- * the return value of {@link #getTarget()}.
+ *
In that case, there will be no need to invoke {@link #releaseTarget(Object)},
+ * and the AOP framework can cache the return value of {@link #getTarget()}.
* @return {@code true} if the target is immutable
* @see #getTarget
*/
@@ -55,14 +53,15 @@ public interface TargetSource extends TargetClassAware {
/**
* Return a target instance. Invoked immediately before the
* AOP framework calls the "target" of an AOP method invocation.
- * @return the target object, which contains the joinpoint
+ * @return the target object which contains the joinpoint,
+ * or {@code null} if there is no actual target instance
* @throws Exception if the target object can't be resolved
*/
Object getTarget() throws Exception;
/**
* Release the given target object obtained from the
- * {@link #getTarget()} method.
+ * {@link #getTarget()} method, if any.
* @param target object obtained from a call to {@link #getTarget()}
* @throws Exception if the object can't be released
*/
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java
index c7575168899..a5ed7d1131b 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -103,8 +103,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
private final AspectInstanceFactory aspectInstanceFactory;
/**
- * The name of the aspect (ref bean) in which this advice was defined (used
- * when determining advice precedence so that we can determine
+ * The name of the aspect (ref bean) in which this advice was defined
+ * (used when determining advice precedence so that we can determine
* whether two pieces of advice come from the same aspect).
*/
private String aspectName;
@@ -118,13 +118,13 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
* This will be non-null if the creator of this advice object knows the argument names
* and sets them explicitly
*/
- private String[] argumentNames = null;
+ private String[] argumentNames;
/** Non-null if after throwing advice binds the thrown value */
- private String throwingName = null;
+ private String throwingName;
/** Non-null if after returning advice binds the return value */
- private String returningName = null;
+ private String returningName;
private Class> discoveredReturningType = Object.class;
@@ -295,8 +295,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
}
catch (Throwable ex) {
throw new IllegalArgumentException("Returning name '" + name +
- "' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
- "Root cause: " + ex);
+ "' is neither a valid argument name nor the fully-qualified " +
+ "name of a Java type on the classpath. Root cause: " + ex);
}
}
}
@@ -329,8 +329,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
}
catch (Throwable ex) {
throw new IllegalArgumentException("Throwing name '" + name +
- "' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
- "Root cause: " + ex);
+ "' is neither a valid argument name nor the fully-qualified " +
+ "name of a Java type on the classpath. Root cause: " + ex);
}
}
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java
index 671951324b2..bd1e7a28a23 100644
--- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java
+++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -113,6 +113,7 @@ import org.springframework.util.StringUtils;
* returning {@code null} in the case that the parameter names cannot be discovered.
*
* @author Adrian Colyer
+ * @author Juergen Hoeller
* @since 2.0
*/
public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscoverer {
@@ -154,23 +155,17 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
}
+ /** The pointcut expression associated with the advice, as a simple String */
+ private String pointcutExpression;
+
private boolean raiseExceptions;
- /**
- * If the advice is afterReturning, and binds the return value, this is the parameter name used.
- */
+ /** If the advice is afterReturning, and binds the return value, this is the parameter name used */
private String returningName;
- /**
- * If the advice is afterThrowing, and binds the thrown value, this is the parameter name used.
- */
+ /** If the advice is afterThrowing, and binds the thrown value, this is the parameter name used */
private String throwingName;
- /**
- * The pointcut expression associated with the advice, as a simple String.
- */
- private String pointcutExpression;
-
private Class>[] argumentTypes;
private String[] parameterNameBindings;
@@ -186,6 +181,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
this.pointcutExpression = pointcutExpression;
}
+
/**
* Indicate whether {@link IllegalArgumentException} and {@link AmbiguousBindingException}
* must be thrown as appropriate in the case of failing to deduce advice parameter names.
@@ -213,6 +209,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
this.throwingName = throwingName;
}
+
/**
* Deduce the parameter names for an advice method.
*
See the {@link AspectJAdviceParameterNameDiscoverer class level javadoc}
@@ -474,7 +471,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
* If the token starts meets Java identifier conventions, it's in.
*/
private String maybeExtractVariableName(String candidateToken) {
- if (candidateToken == null || candidateToken.equals("")) {
+ if (!StringUtils.hasLength(candidateToken)) {
return null;
}
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
index 0174ab0aa73..6a8fc97da4d 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -454,10 +454,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
}
Advisor[] advisors = buildAdvisors(beanName, specificInterceptors);
- for (Advisor advisor : advisors) {
- proxyFactory.addAdvisor(advisor);
- }
-
+ proxyFactory.addAdvisors(advisors);
proxyFactory.setTargetSource(targetSource);
customizeProxyFactory(proxyFactory);
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java
index fd78bfd6048..50a67d2ae2f 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -22,7 +22,6 @@ import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.util.Assert;
-import org.springframework.util.ObjectUtils;
/**
* Convenient class for building up pointcuts. All methods return
@@ -188,21 +187,14 @@ public class ComposablePointcut implements Pointcut, Serializable {
if (!(other instanceof ComposablePointcut)) {
return false;
}
- ComposablePointcut that = (ComposablePointcut) other;
- return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
- ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
+ ComposablePointcut otherPointcut = (ComposablePointcut) other;
+ return (this.classFilter.equals(otherPointcut.classFilter) &&
+ this.methodMatcher.equals(otherPointcut.methodMatcher));
}
@Override
public int hashCode() {
- int code = 17;
- if (this.classFilter != null) {
- code = 37 * code + this.classFilter.hashCode();
- }
- if (this.methodMatcher != null) {
- code = 37 * code + this.methodMatcher.hashCode();
- }
- return code;
+ return this.classFilter.hashCode() * 37 + this.methodMatcher.hashCode();
}
@Override
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java
index 479c31dfa55..5a59d87f4f6 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java
index 59619830d92..ef2790d6f7d 100644
--- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java
+++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -22,7 +22,6 @@ import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.util.Assert;
-import org.springframework.util.ObjectUtils;
/**
* Simple Pointcut that looks for a specific Java 5 annotation
@@ -46,16 +45,15 @@ public class AnnotationMatchingPointcut implements Pointcut {
* @param classAnnotationType the annotation type to look for at the class level
*/
public AnnotationMatchingPointcut(Class extends Annotation> classAnnotationType) {
- this.classFilter = new AnnotationClassFilter(classAnnotationType);
- this.methodMatcher = MethodMatcher.TRUE;
+ this(classAnnotationType, false);
}
/**
* Create a new AnnotationMatchingPointcut for the given annotation type.
* @param classAnnotationType the annotation type to look for at the class level
- * @param checkInherited whether to explicitly check the superclasses and
- * interfaces for the annotation type as well (even if the annotation type
- * is not marked as inherited itself)
+ * @param checkInherited whether to also check the superclasses and interfaces
+ * as well as meta-annotations for the annotation type
+ * @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
*/
public AnnotationMatchingPointcut(Class extends Annotation> classAnnotationType, boolean checkInherited) {
this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);
@@ -109,21 +107,14 @@ public class AnnotationMatchingPointcut implements Pointcut {
if (!(other instanceof AnnotationMatchingPointcut)) {
return false;
}
- AnnotationMatchingPointcut that = (AnnotationMatchingPointcut) other;
- return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
- ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
+ AnnotationMatchingPointcut otherPointcut = (AnnotationMatchingPointcut) other;
+ return (this.classFilter.equals(otherPointcut.classFilter) &&
+ this.methodMatcher.equals(otherPointcut.methodMatcher));
}
@Override
public int hashCode() {
- int code = 17;
- if (this.classFilter != null) {
- code = 37 * code + this.classFilter.hashCode();
- }
- if (this.methodMatcher != null) {
- code = 37 * code + this.methodMatcher.hashCode();
- }
- return code;
+ return this.classFilter.hashCode() * 37 + this.methodMatcher.hashCode();
}
@Override
diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java
index c7faf35524e..fe9151805cf 100644
--- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -81,8 +81,6 @@ public interface PropertyAccessor {
* (may be a nested path and/or an indexed/mapped property)
* @return the property type for the particular property,
* or {@code null} if not determinable
- * @throws InvalidPropertyException if there is no such property or
- * if the property isn't readable
* @throws PropertyAccessException if the property was valid but the
* accessor method failed
*/
@@ -95,8 +93,8 @@ public interface PropertyAccessor {
* (may be a nested path and/or an indexed/mapped property)
* @return the property type for the particular property,
* or {@code null} if not determinable
- * @throws InvalidPropertyException if there is no such property or
- * if the property isn't readable
+ * @throws PropertyAccessException if the property was valid but the
+ * accessor method failed
*/
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
index f3e418abb23..83498c333e3 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -158,6 +158,22 @@ public interface BeanFactory {
*/
T getBean(String name, Class requiredType) throws BeansException;
+ /**
+ * Return an instance, which may be shared or independent, of the specified bean.
+ * Allows for specifying explicit constructor arguments / factory method arguments,
+ * overriding the specified default arguments (if any) in the bean definition.
+ * @param name the name of the bean to retrieve
+ * @param args arguments to use when creating a bean instance using explicit arguments
+ * (only applied when creating a new instance as opposed to retrieving an existing one)
+ * @return an instance of the bean
+ * @throws NoSuchBeanDefinitionException if there is no such bean definition
+ * @throws BeanDefinitionStoreException if arguments have been given but
+ * the affected bean isn't a prototype
+ * @throws BeansException if the bean could not be created
+ * @since 2.5
+ */
+ Object getBean(String name, Object... args) throws BeansException;
+
/**
* Return the bean instance that uniquely matches the given object type, if any.
*
This method goes into {@link ListableBeanFactory} by-type lookup territory
@@ -175,22 +191,6 @@ public interface BeanFactory {
*/
T getBean(Class requiredType) throws BeansException;
- /**
- * Return an instance, which may be shared or independent, of the specified bean.
- * Allows for specifying explicit constructor arguments / factory method arguments,
- * overriding the specified default arguments (if any) in the bean definition.
- * @param name the name of the bean to retrieve
- * @param args arguments to use when creating a bean instance using explicit arguments
- * (only applied when creating a new instance as opposed to retrieving an existing one)
- * @return an instance of the bean
- * @throws NoSuchBeanDefinitionException if there is no such bean definition
- * @throws BeanDefinitionStoreException if arguments have been given but
- * the affected bean isn't a prototype
- * @throws BeansException if the bean could not be created
- * @since 2.5
- */
- Object getBean(String name, Object... args) throws BeansException;
-
/**
* Return an instance, which may be shared or independent, of the specified bean.
*
Allows for specifying explicit constructor arguments / factory method arguments,
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java
index 92345d7eab9..729abc7cc56 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -281,15 +281,15 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFacto
@SuppressWarnings("unchecked")
protected Constructor determineServiceLocatorExceptionConstructor(Class extends Exception> exceptionClass) {
try {
- return (Constructor) exceptionClass.getConstructor(new Class>[] {String.class, Throwable.class});
+ return (Constructor) exceptionClass.getConstructor(String.class, Throwable.class);
}
catch (NoSuchMethodException ex) {
try {
- return (Constructor) exceptionClass.getConstructor(new Class>[] {Throwable.class});
+ return (Constructor) exceptionClass.getConstructor(Throwable.class);
}
catch (NoSuchMethodException ex2) {
try {
- return (Constructor) exceptionClass.getConstructor(new Class>[] {String.class});
+ return (Constructor) exceptionClass.getConstructor(String.class);
}
catch (NoSuchMethodException ex3) {
throw new IllegalArgumentException(
@@ -357,7 +357,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFacto
return System.identityHashCode(proxy);
}
else if (ReflectionUtils.isToStringMethod(method)) {
- return "Service locator: " + serviceLocatorInterface.getName();
+ return "Service locator: " + serviceLocatorInterface;
}
else {
return invokeServiceLocatorMethod(method, args);
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java
index 64689f6486c..95f81d8a9fc 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * Copyright 2002-2017 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,6 +37,13 @@ public class ReaderContext {
private final SourceExtractor sourceExtractor;
+ /**
+ * Construct a new {@code ReaderContext}.
+ * @param resource the XML bean definition resource
+ * @param problemReporter the problem reporter in use
+ * @param eventListener the event listener in use
+ * @param sourceExtractor the source extractor in use
+ */
public ReaderContext(Resource resource, ProblemReporter problemReporter,
ReaderEventListener eventListener, SourceExtractor sourceExtractor) {
@@ -51,83 +58,150 @@ public class ReaderContext {
}
+ // Errors and warnings
+
+ /**
+ * Raise a fatal error.
+ */
public void fatal(String message, Object source) {
fatal(message, source, null, null);
}
+ /**
+ * Raise a fatal error.
+ */
public void fatal(String message, Object source, Throwable ex) {
fatal(message, source, null, ex);
}
+ /**
+ * Raise a fatal error.
+ */
public void fatal(String message, Object source, ParseState parseState) {
fatal(message, source, parseState, null);
}
+ /**
+ * Raise a fatal error.
+ */
public void fatal(String message, Object source, ParseState parseState, Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.fatal(new Problem(message, location, parseState, cause));
}
+ /**
+ * Raise a regular error.
+ */
public void error(String message, Object source) {
error(message, source, null, null);
}
+ /**
+ * Raise a regular error.
+ */
public void error(String message, Object source, Throwable ex) {
error(message, source, null, ex);
}
+ /**
+ * Raise a regular error.
+ */
public void error(String message, Object source, ParseState parseState) {
error(message, source, parseState, null);
}
+ /**
+ * Raise a regular error.
+ */
public void error(String message, Object source, ParseState parseState, Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.error(new Problem(message, location, parseState, cause));
}
+ /**
+ * Raise a non-critical warning.
+ */
public void warning(String message, Object source) {
warning(message, source, null, null);
}
+ /**
+ * Raise a non-critical warning.
+ */
public void warning(String message, Object source, Throwable ex) {
warning(message, source, null, ex);
}
+ /**
+ * Raise a non-critical warning.
+ */
public void warning(String message, Object source, ParseState parseState) {
warning(message, source, parseState, null);
}
+ /**
+ * Raise a non-critical warning.
+ */
public void warning(String message, Object source, ParseState parseState, Throwable cause) {
Location location = new Location(getResource(), source);
this.problemReporter.warning(new Problem(message, location, parseState, cause));
}
+ // Explicit parse events
+
+ /**
+ * Fire an defaults-registered event.
+ */
public void fireDefaultsRegistered(DefaultsDefinition defaultsDefinition) {
this.eventListener.defaultsRegistered(defaultsDefinition);
}
+ /**
+ * Fire an component-registered event.
+ */
public void fireComponentRegistered(ComponentDefinition componentDefinition) {
this.eventListener.componentRegistered(componentDefinition);
}
+ /**
+ * Fire an alias-registered event.
+ */
public void fireAliasRegistered(String beanName, String alias, Object source) {
this.eventListener.aliasRegistered(new AliasDefinition(beanName, alias, source));
}
+ /**
+ * Fire an import-processed event.
+ */
public void fireImportProcessed(String importedResource, Object source) {
this.eventListener.importProcessed(new ImportDefinition(importedResource, source));
}
+ /**
+ * Fire an import-processed event.
+ */
public void fireImportProcessed(String importedResource, Resource[] actualResources, Object source) {
this.eventListener.importProcessed(new ImportDefinition(importedResource, actualResources, source));
}
+ // Source extraction
+
+ /**
+ * Return the source extractor in use.
+ */
public SourceExtractor getSourceExtractor() {
return this.sourceExtractor;
}
+ /**
+ * Call the source extractor for the given source object.
+ * @param sourceCandidate the original source object
+ * @return the source object to store, or {@code null} for none.
+ * @see #getSourceExtractor()
+ * @see SourceExtractor#extractSource
+ */
public Object extractSource(Object sourceCandidate) {
return this.sourceExtractor.extractSource(sourceCandidate, this.resource);
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java
index db7ccda8001..2ca5393169b 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -62,7 +62,7 @@ public class BeanDefinitionDefaults {
}
public void setInitMethodName(String initMethodName) {
- this.initMethodName = (StringUtils.hasText(initMethodName)) ? initMethodName : null;
+ this.initMethodName = (StringUtils.hasText(initMethodName) ? initMethodName : null);
}
public String getInitMethodName() {
@@ -70,7 +70,7 @@ public class BeanDefinitionDefaults {
}
public void setDestroyMethodName(String destroyMethodName) {
- this.destroyMethodName = (StringUtils.hasText(destroyMethodName)) ? destroyMethodName : null;
+ this.destroyMethodName = (StringUtils.hasText(destroyMethodName) ? destroyMethodName : null);
}
public String getDestroyMethodName() {
diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ResourceBundleEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ResourceBundleEditor.java
index 7eabc102b7a..5ec38eb7dcb 100644
--- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ResourceBundleEditor.java
+++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ResourceBundleEditor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -96,8 +96,7 @@ public class ResourceBundleEditor extends PropertyEditorSupport {
}
String localeString = name.substring(separator + 1);
Locale locale = StringUtils.parseLocaleString(localeString);
- setValue((StringUtils.hasText(localeString)) ? ResourceBundle.getBundle(baseName, locale) :
- ResourceBundle.getBundle(baseName));
+ setValue(locale != null ? ResourceBundle.getBundle(baseName, locale) : ResourceBundle.getBundle(baseName));
}
}
diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java
index c80330846e5..314f329e390 100644
--- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java
+++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -110,8 +110,7 @@ public class JCacheCache extends AbstractValueAdaptingCache {
@SuppressWarnings("unchecked")
@Override
- public T process(MutableEntry entry, Object... arguments)
- throws EntryProcessorException {
+ public T process(MutableEntry entry, Object... arguments) throws EntryProcessorException {
Callable valueLoader = (Callable) arguments[0];
if (entry.exists()) {
return (T) fromStoreValue(entry.getValue());
diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java
index 8e960c85e18..ee25a1090ab 100644
--- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java
+++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java
@@ -94,7 +94,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial
protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) {
// Check whether aspect is enabled to cope with cases where the AJ is pulled in automatically
if (this.initialized) {
- Class> targetClass = getTargetClass(target);
+ Class> targetClass = AopProxyUtils.ultimateTargetClass(target);
JCacheOperation> operation = getCacheOperationSource().getCacheOperation(method, targetClass);
if (operation != null) {
CacheOperationInvocationContext> context =
@@ -114,14 +114,6 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial
(JCacheOperation) operation, target, args);
}
- private Class> getTargetClass(Object target) {
- Class> targetClass = AopProxyUtils.ultimateTargetClass(target);
- if (targetClass == null && target != null) {
- targetClass = target.getClass();
- }
- return targetClass;
- }
-
@SuppressWarnings("unchecked")
private Object execute(CacheOperationInvocationContext> context, CacheOperationInvoker invoker) {
CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker);
diff --git a/spring-context-support/src/main/java/org/springframework/mail/MailMessage.java b/spring-context-support/src/main/java/org/springframework/mail/MailMessage.java
index c33f0e76b24..95590362111 100644
--- a/spring-context-support/src/main/java/org/springframework/mail/MailMessage.java
+++ b/spring-context-support/src/main/java/org/springframework/mail/MailMessage.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2005 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -35,26 +35,26 @@ import java.util.Date;
*/
public interface MailMessage {
- public void setFrom(String from) throws MailParseException;
+ void setFrom(String from) throws MailParseException;
- public void setReplyTo(String replyTo) throws MailParseException;
+ void setReplyTo(String replyTo) throws MailParseException;
- public void setTo(String to) throws MailParseException;
+ void setTo(String to) throws MailParseException;
- public void setTo(String[] to) throws MailParseException;
+ void setTo(String[] to) throws MailParseException;
- public void setCc(String cc) throws MailParseException;
+ void setCc(String cc) throws MailParseException;
- public void setCc(String[] cc) throws MailParseException;
+ void setCc(String[] cc) throws MailParseException;
- public void setBcc(String bcc) throws MailParseException;
+ void setBcc(String bcc) throws MailParseException;
- public void setBcc(String[] bcc) throws MailParseException;
+ void setBcc(String[] bcc) throws MailParseException;
- public void setSentDate(Date sentDate) throws MailParseException;
+ void setSentDate(Date sentDate) throws MailParseException;
- public void setSubject(String subject) throws MailParseException;
+ void setSubject(String subject) throws MailParseException;
- public void setText(String text) throws MailParseException;
+ void setText(String text) throws MailParseException;
}
diff --git a/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java b/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java
index bca30499d95..c249ca3fcf8 100644
--- a/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java
+++ b/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -68,10 +68,9 @@ public class SimpleMailMessage implements MailMessage, Serializable {
/**
* Copy constructor for creating a new {@code SimpleMailMessage} from the state
* of an existing {@code SimpleMailMessage} instance.
- * @throws IllegalArgumentException if the supplied message is {@code null}
*/
public SimpleMailMessage(SimpleMailMessage original) {
- Assert.notNull(original, "The 'original' message argument cannot be null");
+ Assert.notNull(original, "'original' message argument must not be null");
this.from = original.getFrom();
this.replyTo = original.getReplyTo();
if (original.getTo() != null) {
@@ -104,7 +103,7 @@ public class SimpleMailMessage implements MailMessage, Serializable {
}
public String getReplyTo() {
- return replyTo;
+ return this.replyTo;
}
@Override
@@ -132,7 +131,7 @@ public class SimpleMailMessage implements MailMessage, Serializable {
}
public String[] getCc() {
- return cc;
+ return this.cc;
}
@Override
@@ -146,7 +145,7 @@ public class SimpleMailMessage implements MailMessage, Serializable {
}
public String[] getBcc() {
- return bcc;
+ return this.bcc;
}
@Override
@@ -155,7 +154,7 @@ public class SimpleMailMessage implements MailMessage, Serializable {
}
public Date getSentDate() {
- return sentDate;
+ return this.sentDate;
}
@Override
diff --git a/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java
index d9f90dc2f14..6a0745e5b52 100644
--- a/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java
+++ b/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -201,16 +201,16 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
private static void registerCacheAdvisor(Element element, ParserContext parserContext) {
if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME)) {
- Object eleSource = parserContext.extractSource(element);
+ Object source = parserContext.extractSource(element);
// Create the CacheOperationSource definition.
- BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, eleSource);
+ BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, source);
String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);
// Create the CacheInterceptor definition.
RootBeanDefinition interceptorDef =
new RootBeanDefinition("org.springframework.cache.jcache.interceptor.JCacheInterceptor");
- interceptorDef.setSource(eleSource);
+ interceptorDef.setSource(source);
interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
interceptorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
parseErrorHandler(element, interceptorDef);
@@ -219,7 +219,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
// Create the CacheAdvisor definition.
RootBeanDefinition advisorDef = new RootBeanDefinition(
"org.springframework.cache.jcache.interceptor.BeanFactoryJCacheOperationSourceAdvisor");
- advisorDef.setSource(eleSource);
+ advisorDef.setSource(source);
advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
@@ -228,7 +228,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
}
parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME, advisorDef);
- CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
+ CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);
compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME));
diff --git a/spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java b/spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java
index f4a626a7ecb..9cf1037e6f3 100644
--- a/spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java
+++ b/spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -196,7 +196,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
private String method;
- private String[] caches = null;
+ private String[] caches;
Props(Element root) {
String defaultCache = root.getAttribute("cache");
diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
index 2d1121a55c6..e1fef7a48a5 100644
--- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
+++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -164,7 +164,6 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
* @see SimpleCacheResolver
*/
public void setCacheResolver(CacheResolver cacheResolver) {
- Assert.notNull(cacheResolver, "CacheResolver must not be null");
this.cacheResolver = cacheResolver;
}
diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluator.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluator.java
index 9111bab0ca6..33257bcb715 100644
--- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluator.java
+++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -140,9 +140,6 @@ class CacheOperationExpressionEvaluator extends CachedExpressionEvaluator {
Method targetMethod = this.targetMethodCache.get(methodKey);
if (targetMethod == null) {
targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
- if (targetMethod == null) {
- targetMethod = method;
- }
this.targetMethodCache.put(methodKey, targetMethod);
}
return targetMethod;
diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java
index e7704cd359c..64224f3b61e 100644
--- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java
+++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2012 the original author or authors.
+ * Copyright 2010-2017 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.
@@ -35,6 +35,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
* of the Spring reference documentation for more information.
*
* @author Costin Leau
+ * @author Juergen Hoeller
* @since 3.1
* @see org.springframework.aop.framework.ProxyFactoryBean
* @see CacheInterceptor
@@ -44,9 +45,16 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean {
private final CacheInterceptor cachingInterceptor = new CacheInterceptor();
- private Pointcut pointcut;
+ private Pointcut pointcut = Pointcut.TRUE;
+ /**
+ * Set the sources used to find cache operations.
+ */
+ public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
+ this.cachingInterceptor.setCacheOperationSources(cacheOperationSources);
+ }
+
/**
* Set a pointcut, i.e a bean that can cause conditional invocation
* of the CacheInterceptor depending on method and attributes passed.
@@ -61,18 +69,7 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean {
@Override
protected Object createMainInterceptor() {
this.cachingInterceptor.afterPropertiesSet();
- if (this.pointcut == null) {
- // Rely on default pointcut.
- throw new UnsupportedOperationException();
- }
return new DefaultPointcutAdvisor(this.pointcut, this.cachingInterceptor);
}
- /**
- * Set the sources used to find cache operations.
- */
- public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
- this.cachingInterceptor.setCacheOperationSources(cacheOperationSources);
- }
-
}
diff --git a/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java b/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java
index eab581da25c..1514ccdfccb 100644
--- a/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java
+++ b/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -19,10 +19,10 @@ package org.springframework.cache.support;
import java.util.concurrent.Callable;
import org.springframework.cache.Cache;
+import org.springframework.util.Assert;
/**
- * A no operation {@link Cache} implementation suitable
- * for disabling caching.
+ * A no operation {@link Cache} implementation suitable for disabling caching.
*
* Will simply accept any items into the cache not actually storing them.
*
@@ -34,20 +34,25 @@ public class NoOpCache implements Cache {
private final String name;
+
/**
* Create a {@link NoOpCache} instance with the specified name
* @param name the name of the cache
*/
public NoOpCache(String name) {
+ Assert.notNull(name, "Cache name must not be null");
this.name = name;
}
+
@Override
- public void clear() {
+ public String getName() {
+ return this.name;
}
@Override
- public void evict(Object key) {
+ public Object getNativeCache() {
+ return null;
}
@Override
@@ -70,16 +75,6 @@ public class NoOpCache implements Cache {
}
}
- @Override
- public String getName() {
- return this.name;
- }
-
- @Override
- public Object getNativeCache() {
- return null;
- }
-
@Override
public void put(Object key, Object value) {
}
@@ -89,4 +84,12 @@ public class NoOpCache implements Cache {
return null;
}
+ @Override
+ public void evict(Object key) {
+ }
+
+ @Override
+ public void clear() {
+ }
+
}
diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java
index 1fbbd23bfc7..b01dd9d8b45 100644
--- a/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java
+++ b/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java
@@ -66,8 +66,8 @@ class ComponentScanAnnotationParser {
public ComponentScanAnnotationParser(Environment environment, ResourceLoader resourceLoader,
BeanNameGenerator beanNameGenerator, BeanDefinitionRegistry registry) {
- this.resourceLoader = resourceLoader;
this.environment = environment;
+ this.resourceLoader = resourceLoader;
this.beanNameGenerator = beanNameGenerator;
this.registry = registry;
}
diff --git a/spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java b/spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java
index b934db9403c..12b3ad845e4 100644
--- a/spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java
+++ b/spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -121,7 +121,7 @@ public class MBeanExportConfiguration implements ImportAware, EnvironmentAware,
}
- public static enum SpecificPlatform {
+ public enum SpecificPlatform {
WEBLOGIC("weblogic.management.Helper") {
@Override
@@ -146,7 +146,7 @@ public class MBeanExportConfiguration implements ImportAware, EnvironmentAware,
private final String identifyingClass;
- private SpecificPlatform(String identifyingClass) {
+ SpecificPlatform(String identifyingClass) {
this.identifyingClass = identifyingClass;
}
diff --git a/spring-context/src/main/java/org/springframework/context/event/EventExpressionEvaluator.java b/spring-context/src/main/java/org/springframework/context/event/EventExpressionEvaluator.java
index 8cb00fe8241..a043c3b2b1a 100644
--- a/spring-context/src/main/java/org/springframework/context/event/EventExpressionEvaluator.java
+++ b/spring-context/src/main/java/org/springframework/context/event/EventExpressionEvaluator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -68,8 +68,8 @@ class EventExpressionEvaluator extends CachedExpressionEvaluator {
public boolean condition(String conditionExpression,
AnnotatedElementKey elementKey, EvaluationContext evalContext) {
- return getExpression(this.conditionCache, elementKey, conditionExpression)
- .getValue(evalContext, boolean.class);
+ return getExpression(this.conditionCache, elementKey, conditionExpression).getValue(
+ evalContext, boolean.class);
}
private Method getTargetMethod(Class> targetClass, Method method) {
@@ -77,9 +77,6 @@ class EventExpressionEvaluator extends CachedExpressionEvaluator {
Method targetMethod = this.targetMethodCache.get(methodKey);
if (targetMethod == null) {
targetMethod = AopUtils.getMostSpecificMethod(method, targetClass);
- if (targetMethod == null) {
- targetMethod = method;
- }
this.targetMethodCache.put(methodKey, targetMethod);
}
return targetMethod;
diff --git a/spring-context/src/main/java/org/springframework/context/event/EventPublicationInterceptor.java b/spring-context/src/main/java/org/springframework/context/event/EventPublicationInterceptor.java
index 259dc150b12..cd46bc8b444 100644
--- a/spring-context/src/main/java/org/springframework/context/event/EventPublicationInterceptor.java
+++ b/spring-context/src/main/java/org/springframework/context/event/EventPublicationInterceptor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -64,15 +64,14 @@ public class EventPublicationInterceptor
*/
public void setApplicationEventClass(Class> applicationEventClass) {
if (ApplicationEvent.class == applicationEventClass ||
- !ApplicationEvent.class.isAssignableFrom(applicationEventClass)) {
- throw new IllegalArgumentException("applicationEventClass needs to extend ApplicationEvent");
+ !ApplicationEvent.class.isAssignableFrom(applicationEventClass)) {
+ throw new IllegalArgumentException("'applicationEventClass' needs to extend ApplicationEvent");
}
try {
- this.applicationEventClassConstructor =
- applicationEventClass.getConstructor(new Class>[] {Object.class});
+ this.applicationEventClassConstructor = applicationEventClass.getConstructor(Object.class);
}
catch (NoSuchMethodException ex) {
- throw new IllegalArgumentException("applicationEventClass [" +
+ throw new IllegalArgumentException("ApplicationEvent class [" +
applicationEventClass.getName() + "] does not have the required Object constructor: " + ex);
}
}
@@ -85,7 +84,7 @@ public class EventPublicationInterceptor
@Override
public void afterPropertiesSet() throws Exception {
if (this.applicationEventClassConstructor == null) {
- throw new IllegalArgumentException("applicationEventClass is required");
+ throw new IllegalArgumentException("Property 'applicationEventClass' is required");
}
}
@@ -95,7 +94,7 @@ public class EventPublicationInterceptor
Object retVal = invocation.proceed();
ApplicationEvent event = (ApplicationEvent)
- this.applicationEventClassConstructor.newInstance(new Object[] {invocation.getThis()});
+ this.applicationEventClassConstructor.newInstance(invocation.getThis());
this.applicationEventPublisher.publishEvent(event);
return retVal;
diff --git a/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListenerAdapter.java b/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListenerAdapter.java
index 7f27f1c6025..b1ea938529f 100644
--- a/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListenerAdapter.java
+++ b/spring-context/src/main/java/org/springframework/context/event/GenericApplicationListenerAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -75,12 +75,8 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList
@Override
public boolean supportsSourceType(Class> sourceType) {
- if (this.delegate instanceof SmartApplicationListener) {
- return ((SmartApplicationListener) this.delegate).supportsSourceType(sourceType);
- }
- else {
- return true;
- }
+ return !(this.delegate instanceof SmartApplicationListener) ||
+ ((SmartApplicationListener) this.delegate).supportsSourceType(sourceType);
}
@Override
@@ -91,17 +87,13 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList
static ResolvableType resolveDeclaredEventType(Class> listenerType) {
ResolvableType resolvableType = ResolvableType.forClass(listenerType).as(ApplicationListener.class);
- if (resolvableType == null || !resolvableType.hasGenerics()) {
- return null;
- }
- return resolvableType.getGeneric();
+ return (resolvableType.hasGenerics() ? resolvableType.getGeneric() : null);
}
private static ResolvableType resolveDeclaredEventType(ApplicationListener listener) {
ResolvableType declaredEventType = resolveDeclaredEventType(listener.getClass());
if (declaredEventType == null || declaredEventType.isAssignableFrom(
ResolvableType.forClass(ApplicationEvent.class))) {
-
Class> targetClass = AopUtils.getTargetClass(listener);
if (targetClass != listener.getClass()) {
declaredEventType = resolveDeclaredEventType(targetClass);
diff --git a/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java b/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java
index 50812c11c02..348e249d869 100644
--- a/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java
+++ b/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -75,6 +75,9 @@ public final class AnnotatedElementKey implements Comparable 0 ? this.codes[this.codes.length - 1] : null);
}
+ @Override
+ public String[] getCodes() {
+ return this.codes;
+ }
+
@Override
public Object[] getArguments() {
return this.arguments;
diff --git a/spring-context/src/main/java/org/springframework/context/support/MessageSourceAccessor.java b/spring-context/src/main/java/org/springframework/context/support/MessageSourceAccessor.java
index 03fa94a5256..00ca6ad2001 100644
--- a/spring-context/src/main/java/org/springframework/context/support/MessageSourceAccessor.java
+++ b/spring-context/src/main/java/org/springframework/context/support/MessageSourceAccessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -40,6 +40,7 @@ public class MessageSourceAccessor {
private final Locale defaultLocale;
+
/**
* Create a new MessageSourceAccessor, using LocaleContextHolder's locale
* as default locale.
@@ -61,6 +62,7 @@ public class MessageSourceAccessor {
this.defaultLocale = defaultLocale;
}
+
/**
* Return the default locale to use if no explicit locale has been given.
* The default implementation returns the default locale passed into the
diff --git a/spring-context/src/main/java/org/springframework/context/support/SimpleThreadScope.java b/spring-context/src/main/java/org/springframework/context/support/SimpleThreadScope.java
index 14357c9f747..9dbd8a653c8 100644
--- a/spring-context/src/main/java/org/springframework/context/support/SimpleThreadScope.java
+++ b/spring-context/src/main/java/org/springframework/context/support/SimpleThreadScope.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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,12 +67,12 @@ public class SimpleThreadScope implements Scope {
@Override
public Object get(String name, ObjectFactory> objectFactory) {
Map scope = this.threadScope.get();
- Object object = scope.get(name);
- if (object == null) {
- object = objectFactory.getObject();
- scope.put(name, object);
+ Object scopedObject = scope.get(name);
+ if (scopedObject == null) {
+ scopedObject = objectFactory.getObject();
+ scope.put(name, scopedObject);
}
- return object;
+ return scopedObject;
}
@Override
diff --git a/spring-context/src/main/java/org/springframework/format/number/CurrencyStyleFormatter.java b/spring-context/src/main/java/org/springframework/format/number/CurrencyStyleFormatter.java
index 0dbe143d084..d6c049ccdfd 100644
--- a/spring-context/src/main/java/org/springframework/format/number/CurrencyStyleFormatter.java
+++ b/spring-context/src/main/java/org/springframework/format/number/CurrencyStyleFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -72,7 +72,7 @@ public class CurrencyStyleFormatter extends AbstractNumberFormatter {
}
/**
- * Sets the pattern to use to format number values.
+ * Specify the pattern to use to format number values.
* If not specified, the default DecimalFormat pattern is used.
* @see java.text.DecimalFormat#applyPattern(String)
*/
diff --git a/spring-context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java b/spring-context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java
index 837b2ec93de..431c3420821 100644
--- a/spring-context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java
+++ b/spring-context/src/main/java/org/springframework/format/number/NumberFormatAnnotationFormatterFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
diff --git a/spring-context/src/main/java/org/springframework/format/number/NumberStyleFormatter.java b/spring-context/src/main/java/org/springframework/format/number/NumberStyleFormatter.java
index 15b7ee107cd..e92c5f343a8 100644
--- a/spring-context/src/main/java/org/springframework/format/number/NumberStyleFormatter.java
+++ b/spring-context/src/main/java/org/springframework/format/number/NumberStyleFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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 NumberStyleFormatter extends AbstractNumberFormatter {
/**
- * Sets the pattern to use to format number values.
+ * Specify the pattern to use to format number values.
* If not specified, the default DecimalFormat pattern is used.
* @see java.text.DecimalFormat#applyPattern(String)
*/
diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java
index 0763c0eeb37..f49b3e11e98 100644
--- a/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java
+++ b/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java
@@ -48,10 +48,20 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
private final Method copyMethod;
+ /**
+ * Create a new instance of the {@link GlassFishLoadTimeWeaver} class using
+ * the default {@link ClassLoader class loader}.
+ * @see org.springframework.util.ClassUtils#getDefaultClassLoader()
+ */
public GlassFishLoadTimeWeaver() {
this(ClassUtils.getDefaultClassLoader());
}
+ /**
+ * Create a new instance of the {@link GlassFishLoadTimeWeaver} class using
+ * the supplied {@link ClassLoader}.
+ * @param classLoader the {@code ClassLoader} to delegate to for weaving
+ */
public GlassFishLoadTimeWeaver(ClassLoader classLoader) {
Assert.notNull(classLoader, "ClassLoader must not be null");
diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassPreProcessorAdapter.java b/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassPreProcessorAdapter.java
index c7093c7bd87..ada8e4c2d2b 100644
--- a/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassPreProcessorAdapter.java
+++ b/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassPreProcessorAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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,9 +41,7 @@ class WebLogicClassPreProcessorAdapter implements InvocationHandler {
/**
- * Creates a new {@link WebLogicClassPreProcessorAdapter}.
- * @param transformer the {@link ClassFileTransformer} to be adapted
- * (must not be {@code null})
+ * Construct a new {@link WebLogicClassPreProcessorAdapter}.
*/
public WebLogicClassPreProcessorAdapter(ClassFileTransformer transformer, ClassLoader loader) {
this.transformer = transformer;
diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereLoadTimeWeaver.java
index aeed6929f14..1ec1061cfb7 100644
--- a/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereLoadTimeWeaver.java
+++ b/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereLoadTimeWeaver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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,7 +25,7 @@ import org.springframework.util.ClassUtils;
/**
* {@link LoadTimeWeaver} implementation for WebSphere's instrumentable ClassLoader.
- * Compatible with WebSphere 7 as well as 8.
+ * Compatible with WebSphere 7 as well as 8 and 9.
*
* @author Costin Leau
* @since 3.1
@@ -48,7 +48,6 @@ public class WebSphereLoadTimeWeaver implements LoadTimeWeaver {
* Create a new instance of the {@link WebSphereLoadTimeWeaver} class using
* the supplied {@link ClassLoader}.
* @param classLoader the {@code ClassLoader} to delegate to for weaving
- * (must not be {@code null})
*/
public WebSphereLoadTimeWeaver(ClassLoader classLoader) {
Assert.notNull(classLoader, "ClassLoader must not be null");
diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/InterfaceBasedMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/InterfaceBasedMBeanInfoAssembler.java
index 1356b0eaad0..fcd132b6554 100644
--- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/InterfaceBasedMBeanInfoAssembler.java
+++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/InterfaceBasedMBeanInfoAssembler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -60,21 +60,14 @@ import org.springframework.util.StringUtils;
public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanInfoAssembler
implements BeanClassLoaderAware, InitializingBean {
- /**
- * Stores the array of interfaces to use for creating the management interface.
- */
private Class>[] managedInterfaces;
- /**
- * Stores the mappings of bean keys to an array of {@code Class}es.
- */
+ /** Mappings of bean keys to an array of classes */
private Properties interfaceMappings;
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
- /**
- * Stores the mappings of bean keys to an array of {@code Class}es.
- */
+ /** Mappings of bean keys to an array of classes */
private Map[]> resolvedInterfaceMappings;
@@ -86,7 +79,7 @@ public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanI
* Each entry MUST be an interface.
* @see #setInterfaceMappings
*/
- public void setManagedInterfaces(Class>[] managedInterfaces) {
+ public void setManagedInterfaces(Class>... managedInterfaces) {
if (managedInterfaces != null) {
for (Class> ifc : managedInterfaces) {
if (!ifc.isInterface()) {
@@ -103,7 +96,7 @@ public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanI
* The property key should match the bean key and the property value should match
* the list of interface names. When searching for interfaces for a bean, Spring
* will check these mappings first.
- * @param mappings the mappins of bean keys to interface names
+ * @param mappings the mappings of bean keys to interface names
*/
public void setInterfaceMappings(Properties mappings) {
this.interfaceMappings = mappings;
@@ -230,13 +223,11 @@ public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanI
}
}
- if (ifaces != null) {
- for (Class> ifc : ifaces) {
- for (Method ifcMethod : ifc.getMethods()) {
- if (ifcMethod.getName().equals(method.getName()) &&
- Arrays.equals(ifcMethod.getParameterTypes(), method.getParameterTypes())) {
- return true;
- }
+ for (Class> ifc : ifaces) {
+ for (Method ifcMethod : ifc.getMethods()) {
+ if (ifcMethod.getName().equals(method.getName()) &&
+ Arrays.equals(ifcMethod.getParameterTypes(), method.getParameterTypes())) {
+ return true;
}
}
}
diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MetadataMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MetadataMBeanInfoAssembler.java
index 99cb23953b4..9af730776b3 100644
--- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MetadataMBeanInfoAssembler.java
+++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MetadataMBeanInfoAssembler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -34,18 +34,17 @@ import org.springframework.jmx.export.metadata.ManagedNotification;
import org.springframework.jmx.export.metadata.ManagedOperation;
import org.springframework.jmx.export.metadata.ManagedOperationParameter;
import org.springframework.jmx.export.metadata.ManagedResource;
-import org.springframework.jmx.support.MetricType;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
- * Implementation of the {@link MBeanInfoAssembler}
- * interface that reads the management interface information from source level metadata.
+ * Implementation of the {@link MBeanInfoAssembler} interface that reads
+ * the management interface information from source level metadata.
*
*
Uses the {@link JmxAttributeSource} strategy interface, so that
* metadata can be read using any supported implementation. Out of the box,
- * Spring provides an implementation based on JDK 1.5+ annotations,
+ * Spring provides an implementation based on annotations:
* {@code AnnotationJmxAttributeSource}.
*
* @author Rob Harrop
@@ -339,9 +338,9 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
}
else {
ManagedAttribute gma =
- (getter == null) ? ManagedAttribute.EMPTY : this.attributeSource.getManagedAttribute(getter);
+ (getter == null) ? ManagedAttribute.EMPTY : this.attributeSource.getManagedAttribute(getter);
ManagedAttribute sma =
- (setter == null) ? ManagedAttribute.EMPTY : this.attributeSource.getManagedAttribute(setter);
+ (setter == null) ? ManagedAttribute.EMPTY : this.attributeSource.getManagedAttribute(setter);
populateAttributeDescriptor(desc,gma,sma);
}
}
@@ -384,8 +383,7 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem
desc.setField(FIELD_METRIC_CATEGORY, metric.getCategory());
}
- String metricType = (metric.getMetricType() == null) ? MetricType.GAUGE.toString() : metric.getMetricType().toString();
- desc.setField(FIELD_METRIC_TYPE, metricType);
+ desc.setField(FIELD_METRIC_TYPE, metric.getMetricType().toString());
}
/**
diff --git a/spring-context/src/main/java/org/springframework/jmx/export/metadata/JmxMetadataUtils.java b/spring-context/src/main/java/org/springframework/jmx/export/metadata/JmxMetadataUtils.java
index 3ba7aeeb0ab..7466d7f3342 100644
--- a/spring-context/src/main/java/org/springframework/jmx/export/metadata/JmxMetadataUtils.java
+++ b/spring-context/src/main/java/org/springframework/jmx/export/metadata/JmxMetadataUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2005 the original author or authors.
+ * Copyright 2002-2017 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,6 +18,7 @@ package org.springframework.jmx.export.metadata;
import javax.management.modelmbean.ModelMBeanNotificationInfo;
+import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
@@ -34,16 +35,16 @@ public abstract class JmxMetadataUtils {
* {@link javax.management.modelmbean.ModelMBeanNotificationInfo}.
*/
public static ModelMBeanNotificationInfo convertToModelMBeanNotificationInfo(ManagedNotification notificationInfo) {
+ String[] notifTypes = notificationInfo.getNotificationTypes();
+ if (ObjectUtils.isEmpty(notifTypes)) {
+ throw new IllegalArgumentException("Must specify at least one notification type");
+ }
+
String name = notificationInfo.getName();
if (!StringUtils.hasText(name)) {
throw new IllegalArgumentException("Must specify notification name");
}
- String[] notifTypes = notificationInfo.getNotificationTypes();
- if (notifTypes == null || notifTypes.length == 0) {
- throw new IllegalArgumentException("Must specify at least one notification type");
- }
-
String description = notificationInfo.getDescription();
return new ModelMBeanNotificationInfo(notifTypes, name, description);
}
diff --git a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedMetric.java b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedMetric.java
index f84908a5c3d..38360fe0ea3 100644
--- a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedMetric.java
+++ b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedMetric.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2017 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,6 +17,7 @@
package org.springframework.jmx.export.metadata;
import org.springframework.jmx.support.MetricType;
+import org.springframework.util.Assert;
/**
* Metadata that indicates to expose a given bean property as a JMX attribute,
@@ -74,6 +75,7 @@ public class ManagedMetric extends AbstractJmxAttribute {
* A description of how this metric's values change over time.
*/
public void setMetricType(MetricType metricType) {
+ Assert.notNull(metricType, "MetricType must not be null");
this.metricType = metricType;
}
diff --git a/spring-context/src/main/java/org/springframework/jmx/export/naming/KeyNamingStrategy.java b/spring-context/src/main/java/org/springframework/jmx/export/naming/KeyNamingStrategy.java
index 5cb99a88948..ec6f972e58d 100644
--- a/spring-context/src/main/java/org/springframework/jmx/export/naming/KeyNamingStrategy.java
+++ b/spring-context/src/main/java/org/springframework/jmx/export/naming/KeyNamingStrategy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -105,17 +105,14 @@ public class KeyNamingStrategy implements ObjectNamingStrategy, InitializingBean
* Merges the {@code Properties} configured in the {@code mappings} and
* {@code mappingLocations} into the final {@code Properties} instance
* used for {@code ObjectName} resolution.
- * @throws IOException
*/
@Override
public void afterPropertiesSet() throws IOException {
this.mergedMappings = new Properties();
-
CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);
if (this.mappingLocations != null) {
- for (int i = 0; i < this.mappingLocations.length; i++) {
- Resource location = this.mappingLocations[i];
+ for (Resource location : this.mappingLocations) {
if (logger.isInfoEnabled()) {
logger.info("Loading JMX object name mappings file from " + location);
}
diff --git a/spring-context/src/main/java/org/springframework/jmx/support/MetricType.java b/spring-context/src/main/java/org/springframework/jmx/support/MetricType.java
index 98bba2754fc..8406f8a22d0 100644
--- a/spring-context/src/main/java/org/springframework/jmx/support/MetricType.java
+++ b/spring-context/src/main/java/org/springframework/jmx/support/MetricType.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2017 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,18 +18,19 @@ package org.springframework.jmx.support;
/**
* Represents how the measurement values of a {@code ManagedMetric} will change over time.
+ *
* @author Jennifer Hickey
* @since 3.0
*/
public enum MetricType {
/**
- * The measurement values may go up or down over time
+ * The measurement values may go up or down over time.
*/
GAUGE,
/**
- * The measurement values will always increase
+ * The measurement values will always increase.
*/
COUNTER
diff --git a/spring-context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java b/spring-context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java
index bc508386791..ceb1946189d 100644
--- a/spring-context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java
+++ b/spring-context/src/main/java/org/springframework/jmx/support/NotificationListenerHolder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -73,7 +73,7 @@ public class NotificationListenerHolder {
/**
* Return the {@link javax.management.NotificationFilter} associated
- * with the encapsulated {@link #getNotificationFilter() NotificationFilter}.
+ * with the encapsulated {@link #getNotificationListener() NotificationListener}.
*
May be {@code null}.
*/
public NotificationFilter getNotificationFilter() {
diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java
index 27c6e1ee7f0..62f79ce3b53 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -154,7 +154,7 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
* Provide an {@link ErrorHandler} strategy.
*/
public void setErrorHandler(ErrorHandler errorHandler) {
- Assert.notNull(errorHandler, "'errorHandler' must not be null");
+ Assert.notNull(errorHandler, "ErrorHandler must not be null");
this.errorHandler = errorHandler;
}
@@ -166,7 +166,8 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
return new EnterpriseConcurrentTriggerScheduler().schedule(decorateTask(task, true), trigger);
}
else {
- ErrorHandler errorHandler = (this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
+ ErrorHandler errorHandler =
+ (this.errorHandler != null ? this.errorHandler : TaskUtils.getDefaultErrorHandler(true));
return new ReschedulingRunnable(task, trigger, this.scheduledExecutor, errorHandler).schedule();
}
}
@@ -248,9 +249,9 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T
return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
@Override
public Date getNextRunTime(LastExecution le, Date taskScheduledTime) {
- return trigger.nextExecutionTime(le != null ?
+ return (trigger.nextExecutionTime(le != null ?
new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) :
- new SimpleTriggerContext());
+ new SimpleTriggerContext()));
}
@Override
public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java
index a7ce5fb000c..66482c91b6e 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -196,29 +196,30 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
* Perform a shutdown on the underlying ExecutorService.
* @see java.util.concurrent.ExecutorService#shutdown()
* @see java.util.concurrent.ExecutorService#shutdownNow()
- * @see #awaitTerminationIfNecessary()
*/
public void shutdown() {
if (logger.isInfoEnabled()) {
logger.info("Shutting down ExecutorService" + (this.beanName != null ? " '" + this.beanName + "'" : ""));
}
- if (this.waitForTasksToCompleteOnShutdown) {
- this.executor.shutdown();
+ if (this.executor != null) {
+ if (this.waitForTasksToCompleteOnShutdown) {
+ this.executor.shutdown();
+ }
+ else {
+ this.executor.shutdownNow();
+ }
+ awaitTerminationIfNecessary(this.executor);
}
- else {
- this.executor.shutdownNow();
- }
- awaitTerminationIfNecessary();
}
/**
* Wait for the executor to terminate, according to the value of the
* {@link #setAwaitTerminationSeconds "awaitTerminationSeconds"} property.
*/
- private void awaitTerminationIfNecessary() {
+ private void awaitTerminationIfNecessary(ExecutorService executor) {
if (this.awaitTerminationSeconds > 0) {
try {
- if (!this.executor.awaitTermination(this.awaitTerminationSeconds, TimeUnit.SECONDS)) {
+ if (!executor.awaitTermination(this.awaitTerminationSeconds, TimeUnit.SECONDS)) {
if (logger.isWarnEnabled()) {
logger.warn("Timed out while waiting for executor" +
(this.beanName != null ? " '" + this.beanName + "'" : "") + " to terminate");
diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java
index 01da8e09325..3d960c719d4 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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,10 +67,10 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
private volatile boolean removeOnCancelPolicy = false;
- private volatile ScheduledExecutorService scheduledExecutor;
-
private volatile ErrorHandler errorHandler;
+ private volatile ScheduledExecutorService scheduledExecutor;
+
/**
* Set the ScheduledExecutorService's pool size.
diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java b/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java
index 0c3b029d42f..685ca793ed5 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -116,7 +116,8 @@ public class PeriodicTrigger implements Trigger {
return false;
}
PeriodicTrigger other = (PeriodicTrigger) obj;
- return (this.fixedRate == other.fixedRate && this.initialDelay == other.initialDelay && this.period == other.period);
+ return (this.fixedRate == other.fixedRate && this.initialDelay == other.initialDelay &&
+ this.period == other.period);
}
@Override
diff --git a/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java b/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java
index a0c7f4de3dc..3e572837390 100644
--- a/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java
+++ b/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -271,8 +271,8 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
}
}
catch (Exception ex) {
- if (ex instanceof BeanCreationException
- && ((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
+ if (ex instanceof BeanCreationException &&
+ ((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
if (logger.isTraceEnabled()) {
logger.trace("Could not determine scripted object type for bean '" + beanName + "': "
+ ex.getMessage());
diff --git a/spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java b/spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java
index 0eee6f1bbc7..3690cba0126 100644
--- a/spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java
+++ b/spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -112,6 +112,14 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
this.prefix = (prefix != null ? prefix : "");
}
+ /**
+ * Return the prefix to be applied to any code built by this resolver.
+ *
Returns an empty String in case of no prefix.
+ */
+ protected String getPrefix() {
+ return this.prefix;
+ }
+
/**
* Specify the format for message codes built by this resolver.
*
The default is {@link Format#PREFIX_ERROR_CODE}.
@@ -119,15 +127,7 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
* @see Format
*/
public void setMessageCodeFormatter(MessageCodeFormatter formatter) {
- this.formatter = (formatter == null ? DEFAULT_FORMATTER : formatter);
- }
-
- /**
- * Return the prefix to be applied to any code built by this resolver.
- *
Returns an empty String in case of no prefix.
- */
- protected String getPrefix() {
- return this.prefix;
+ this.formatter = (formatter != null ? formatter : DEFAULT_FORMATTER);
}
@@ -141,7 +141,7 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
* object/field-specific code, a field-specific code, a plain error code.
*
Arrays, Lists and Maps are resolved both for specific elements and
* the whole collection.
- *
See the {@link DefaultMessageCodesResolver class level Javadoc} for
+ *
See the {@link DefaultMessageCodesResolver class level javadoc} for
* details on the generated codes.
* @return the list of codes
*/
@@ -208,14 +208,10 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
/**
* Common message code formats.
- *
- * @author Phillip Webb
- * @author Chris Beams
- * @since 3.2
* @see MessageCodeFormatter
* @see DefaultMessageCodesResolver#setMessageCodeFormatter(MessageCodeFormatter)
*/
- public static enum Format implements MessageCodeFormatter {
+ public enum Format implements MessageCodeFormatter {
/**
* Prefix the error code at the beginning of the generated message code. e.g.:
diff --git a/spring-context/src/main/java/org/springframework/validation/FieldError.java b/spring-context/src/main/java/org/springframework/validation/FieldError.java
index 26852dadf62..f15c7994df6 100644
--- a/spring-context/src/main/java/org/springframework/validation/FieldError.java
+++ b/spring-context/src/main/java/org/springframework/validation/FieldError.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -62,8 +62,7 @@ public class FieldError extends ObjectError {
* @param arguments the array of arguments to be used to resolve this message
* @param defaultMessage the default message to be used to resolve this message
*/
- public FieldError(
- String objectName, String field, Object rejectedValue, boolean bindingFailure,
+ public FieldError(String objectName, String field, Object rejectedValue, boolean bindingFailure,
String[] codes, Object[] arguments, String defaultMessage) {
super(objectName, codes, arguments, defaultMessage);
diff --git a/spring-context/src/main/java/org/springframework/validation/ObjectError.java b/spring-context/src/main/java/org/springframework/validation/ObjectError.java
index 829e93874bd..e03fde6ad87 100644
--- a/spring-context/src/main/java/org/springframework/validation/ObjectError.java
+++ b/spring-context/src/main/java/org/springframework/validation/ObjectError.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -27,9 +27,9 @@ import org.springframework.util.Assert;
* how a message code list is built for an {@code ObjectError}.
*
* @author Juergen Hoeller
+ * @since 10.03.2003
* @see FieldError
* @see DefaultMessageCodesResolver
- * @since 10.03.2003
*/
@SuppressWarnings("serial")
public class ObjectError extends DefaultMessageSourceResolvable {
diff --git a/spring-core/src/main/java/org/springframework/core/MethodClassKey.java b/spring-core/src/main/java/org/springframework/core/MethodClassKey.java
index b837fc6486a..1b832d3aa7d 100644
--- a/spring-core/src/main/java/org/springframework/core/MethodClassKey.java
+++ b/spring-core/src/main/java/org/springframework/core/MethodClassKey.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -75,7 +75,7 @@ public final class MethodClassKey implements Comparable {
int result = this.method.getName().compareTo(other.method.getName());
if (result == 0) {
result = this.method.toString().compareTo(other.method.toString());
- if (result == 0 && this.targetClass != null) {
+ if (result == 0 && this.targetClass != null && other.targetClass != null) {
result = this.targetClass.getName().compareTo(other.targetClass.getName());
}
}
diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java b/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java
index 1f361fbc5d7..85b205c20b9 100644
--- a/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java
+++ b/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -24,7 +24,7 @@ package org.springframework.core;
*
* Users of this interface should be careful in complex hierarchy scenarios, especially
* when the generic type signature of the class changes in sub-classes. It is always
- * possible to return {@code null} to fallback on a default behaviour.
+ * possible to return {@code null} to fallback on a default behavior.
*
* @author Stephane Nicoll
* @since 4.2
diff --git a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java
index 770d77a046b..647cb5bd2da 100644
--- a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java
+++ b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java
@@ -35,19 +35,19 @@ import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;
/**
- * Internal utility class that can be used to obtain wrapped {@link Serializable} variants
- * of {@link java.lang.reflect.Type}s.
+ * Internal utility class that can be used to obtain wrapped {@link Serializable}
+ * variants of {@link java.lang.reflect.Type}s.
*
*
{@link #forField(Field) Fields} or {@link #forMethodParameter(MethodParameter)
- * MethodParameters} can be used as the root source for a serializable type. Alternatively
- * the {@link #forGenericSuperclass(Class) superclass},
+ * MethodParameters} can be used as the root source for a serializable type.
+ * Alternatively the {@link #forGenericSuperclass(Class) superclass},
* {@link #forGenericInterfaces(Class) interfaces} or {@link #forTypeParameters(Class)
* type parameters} or a regular {@link Class} can also be used as source.
*
*
The returned type will either be a {@link Class} or a serializable proxy of
* {@link GenericArrayType}, {@link ParameterizedType}, {@link TypeVariable} or
- * {@link WildcardType}. With the exception of {@link Class} (which is final) calls to
- * methods that return further {@link Type}s (for example
+ * {@link WildcardType}. With the exception of {@link Class} (which is final) calls
+ * to methods that return further {@link Type}s (for example
* {@link GenericArrayType#getGenericComponentType()}) will be automatically wrapped.
*
* @author Phillip Webb
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java
index 2ace4ac0486..d83747fee8c 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedElementUtils.java
@@ -1441,8 +1441,8 @@ public class AnnotatedElementUtils {
*
If this method returns {@code true}, then {@link #getAggregatedResults()}
* must return a non-null value.
* @return {@code true} if this processor supports aggregated results
- * @see #getAggregatedResults
* @since 4.3
+ * @see #getAggregatedResults
*/
boolean aggregates();
@@ -1453,10 +1453,9 @@ public class AnnotatedElementUtils {
* responsible for asking this processor if it {@link #aggregates} results
* and then adding the post-processed results to the list returned by this
* method.
- * @return the list of results aggregated by this processor
- * (never {@code null} unless {@link #aggregates} returns {@code false})
- * @see #aggregates
+ * @return the list of results aggregated by this processor (never {@code null})
* @since 4.3
+ * @see #aggregates
*/
List getAggregatedResults();
}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java
index 0cf257d6c90..55e5653f2b2 100644
--- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java
+++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAttributes.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -243,10 +243,9 @@ public class AnnotationAttributes extends LinkedHashMap {
}
/**
- * Get the value stored under the specified {@code attributeName} as a
- * boolean.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ * Get the value stored under the specified {@code attributeName} as a boolean.
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -256,10 +255,9 @@ public class AnnotationAttributes extends LinkedHashMap {
}
/**
- * Get the value stored under the specified {@code attributeName} as a
- * number.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ * Get the value stored under the specified {@code attributeName} as a number.
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -270,10 +268,9 @@ public class AnnotationAttributes extends LinkedHashMap {
}
/**
- * Get the value stored under the specified {@code attributeName} as an
- * enum.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ * Get the value stored under the specified {@code attributeName} as an enum.
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -284,10 +281,9 @@ public class AnnotationAttributes extends LinkedHashMap {
}
/**
- * Get the value stored under the specified {@code attributeName} as a
- * class.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ * Get the value stored under the specified {@code attributeName} as a class.
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -300,11 +296,10 @@ public class AnnotationAttributes extends LinkedHashMap {
/**
* Get the value stored under the specified {@code attributeName} as an
* array of classes.
- * If the value stored under the specified {@code attributeName} is
- * a class, it will be wrapped in a single-element array before
- * returning it.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ *
If the value stored under the specified {@code attributeName} is a class,
+ * it will be wrapped in a single-element array before returning it.
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -361,8 +356,8 @@ public class AnnotationAttributes extends LinkedHashMap {
/**
* Get the annotation of type {@code annotationType} stored under the
* specified {@code attributeName}.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @param annotationType the expected annotation type; never {@code null}
* @return the annotation
* @throws IllegalArgumentException if the attribute does not exist or
@@ -381,8 +376,8 @@ public class AnnotationAttributes extends LinkedHashMap {
* a single-element array before returning it.
* Note: if you expect an actual array of annotations, invoke
* {@link #getAnnotationArray(String, Class)} instead.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @return the array of {@code AnnotationAttributes}
* @throws IllegalArgumentException if the attribute does not exist or
* if it is not of the expected type
@@ -397,8 +392,8 @@ public class AnnotationAttributes extends LinkedHashMap {
* If the value stored under the specified {@code attributeName} is
* an {@code Annotation}, it will be wrapped in a single-element array
* before returning it.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @param annotationType the expected annotation type; never {@code null}
* @return the annotation array
* @throws IllegalArgumentException if the attribute does not exist or
@@ -419,8 +414,8 @@ public class AnnotationAttributes extends LinkedHashMap {
* component type of the expected array type, the single element will be
* wrapped in a single-element array of the appropriate type before
* returning it.
- * @param attributeName the name of the attribute to get; never
- * {@code null} or empty
+ * @param attributeName the name of the attribute to get;
+ * never {@code null} or empty
* @param expectedType the expected type; never {@code null}
* @return the value
* @throws IllegalArgumentException if the attribute does not exist or
diff --git a/spring-core/src/main/java/org/springframework/core/convert/Property.java b/spring-core/src/main/java/org/springframework/core/convert/Property.java
index 081bb0ee309..e966e7366cd 100644
--- a/spring-core/src/main/java/org/springframework/core/convert/Property.java
+++ b/spring-core/src/main/java/org/springframework/core/convert/Property.java
@@ -207,8 +207,8 @@ public final class Property {
}
private void addAnnotationsToMap(
- Map, Annotation> annotationMap,
- AnnotatedElement object) {
+ Map, Annotation> annotationMap, AnnotatedElement object) {
+
if (object != null) {
for (Annotation annotation : object.getAnnotations()) {
annotationMap.put(annotation.annotationType(), annotation);
diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java
index 878808d7208..c7ff39a3e90 100644
--- a/spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java
+++ b/spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -112,6 +112,10 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
byte[] bytes = (byte[]) (source instanceof byte[] ? source :
this.conversionService.convert(source, sourceType, BYTE_ARRAY_TYPE));
+ if (bytes == null) {
+ return ByteBuffer.wrap(new byte[0]);
+ }
+
ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
byteBuffer.put(bytes);
diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java
index ea79a065b6d..714a4307b8a 100644
--- a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java
+++ b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -40,10 +40,12 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
private final ConversionService conversionService;
+
public CollectionToArrayConverter(ConversionService conversionService) {
this.conversionService = conversionService;
}
+
@Override
public Set getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Collection.class, Object[].class));
@@ -51,7 +53,8 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
- return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), this.conversionService);
+ return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(),
+ targetType.getElementTypeDescriptor(), this.conversionService);
}
@Override
@@ -63,7 +66,8 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter {
Object array = Array.newInstance(targetType.getElementTypeDescriptor().getType(), sourceCollection.size());
int i = 0;
for (Object sourceElement : sourceCollection) {
- Object targetElement = this.conversionService.convert(sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
+ Object targetElement = this.conversionService.convert( sourceElement,
+ sourceType.elementTypeDescriptor(sourceElement), targetType.getElementTypeDescriptor());
Array.set(array, i++, targetElement);
}
return array;
diff --git a/spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java b/spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java
index 453fffcc846..5d28b37a5e3 100644
--- a/spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java
+++ b/spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -50,10 +50,9 @@ abstract class ReadOnlySystemAttributesMap implements Map {
public String get(Object key) {
if (!(key instanceof String)) {
throw new IllegalArgumentException(
- "Type of key [" + (key != null ? key.getClass().getName() : "null") +
- "] must be java.lang.String.");
+ "Type of key [" + key.getClass().getName() + "] must be java.lang.String");
}
- return this.getSystemAttribute((String) key);
+ return getSystemAttribute((String) key);
}
@Override
diff --git a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java
index 94be970e57f..a6ae157ed56 100644
--- a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java
+++ b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -21,6 +21,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
+import org.springframework.util.Assert;
+
/**
* {@link Resource} implementation for a given byte array.
* Creates a {@link ByteArrayInputStream} for the given byte array.
@@ -58,9 +60,7 @@ public class ByteArrayResource extends AbstractResource {
* @param description where the byte array comes from
*/
public ByteArrayResource(byte[] byteArray, String description) {
- if (byteArray == null) {
- throw new IllegalArgumentException("Byte array must not be null");
- }
+ Assert.notNull(byteArray, "Byte array must not be null");
this.byteArray = byteArray;
this.description = (description != null ? description : "");
}
diff --git a/spring-core/src/main/java/org/springframework/core/io/VfsUtils.java b/spring-core/src/main/java/org/springframework/core/io/VfsUtils.java
index 9291cee686f..d66b9a63c49 100644
--- a/spring-core/src/main/java/org/springframework/core/io/VfsUtils.java
+++ b/spring-core/src/main/java/org/springframework/core/io/VfsUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -46,10 +46,10 @@ public abstract class VfsUtils {
private static final String VFS3_PKG = "org.jboss.vfs.";
private static final String VFS_NAME = "VFS";
- private static Method VFS_METHOD_GET_ROOT_URL = null;
- private static Method VFS_METHOD_GET_ROOT_URI = null;
+ private static Method VFS_METHOD_GET_ROOT_URL;
+ private static Method VFS_METHOD_GET_ROOT_URI;
- private static Method VIRTUAL_FILE_METHOD_EXISTS = null;
+ private static Method VIRTUAL_FILE_METHOD_EXISTS;
private static Method VIRTUAL_FILE_METHOD_GET_INPUT_STREAM;
private static Method VIRTUAL_FILE_METHOD_GET_SIZE;
private static Method VIRTUAL_FILE_METHOD_GET_LAST_MODIFIED;
@@ -62,8 +62,8 @@ public abstract class VfsUtils {
protected static Class> VIRTUAL_FILE_VISITOR_INTERFACE;
protected static Method VIRTUAL_FILE_METHOD_VISIT;
- private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null;
- private static Method GET_PHYSICAL_FILE = null;
+ private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE;
+ private static Method GET_PHYSICAL_FILE;
static {
ClassLoader loader = VfsUtils.class.getClassLoader();
@@ -90,7 +90,7 @@ public abstract class VfsUtils {
Class> visitorAttributesClass = loader.loadClass(VFS3_PKG + "VisitorAttributes");
VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
}
- catch (ClassNotFoundException ex) {
+ catch (Throwable ex) {
throw new IllegalStateException("Could not detect JBoss VFS infrastructure", ex);
}
}
diff --git a/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java b/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java
index 09cb9e8cc01..5e327797659 100644
--- a/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java
+++ b/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -404,12 +404,6 @@ public class FastByteArrayOutputStream extends OutputStream {
else if (len == 0) {
return 0;
}
- else if (len < 0) {
- throw new IllegalArgumentException("len must be 0 or greater: " + len);
- }
- else if (off < 0) {
- throw new IllegalArgumentException("off must be 0 or greater: " + off);
- }
else {
if (this.currentBuffer == null) {
// This stream doesn't have any data in it...
diff --git a/spring-core/src/main/java/org/springframework/util/MethodInvoker.java b/spring-core/src/main/java/org/springframework/util/MethodInvoker.java
index d2331caf098..d940242fba9 100644
--- a/spring-core/src/main/java/org/springframework/util/MethodInvoker.java
+++ b/spring-core/src/main/java/org/springframework/util/MethodInvoker.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -122,8 +122,8 @@ public class MethodInvoker {
* Set arguments for the method invocation. If this property is not set,
* or the Object array is of length 0, a method with no arguments is assumed.
*/
- public void setArguments(Object[] arguments) {
- this.arguments = (arguments != null ? arguments : new Object[0]);
+ public void setArguments(Object... arguments) {
+ this.arguments = arguments;
}
/**
@@ -156,12 +156,8 @@ public class MethodInvoker {
Class> targetClass = getTargetClass();
String targetMethod = getTargetMethod();
- if (targetClass == null) {
- throw new IllegalArgumentException("Either 'targetClass' or 'targetObject' is required");
- }
- if (targetMethod == null) {
- throw new IllegalArgumentException("Property 'targetMethod' is required");
- }
+ Assert.notNull(targetClass, "Either 'targetClass' or 'targetObject' is required");
+ Assert.notNull(targetMethod, "Property 'targetMethod' is required");
Object[] arguments = getArguments();
Class>[] argTypes = new Class>[arguments.length];
diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java
index 8209d79b67c..04f3e020b5b 100644
--- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java
+++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -724,12 +724,8 @@ public abstract class ReflectionUtils {
* work on objects with public no-arg constructors.
*/
public static void shallowCopyFieldState(final Object src, final Object dest) {
- if (src == null) {
- throw new IllegalArgumentException("Source for field copy cannot be null");
- }
- if (dest == null) {
- throw new IllegalArgumentException("Destination for field copy cannot be null");
- }
+ Assert.notNull(src, "Source for field copy cannot be null");
+ Assert.notNull(dest, "Destination for field copy cannot be null");
if (!src.getClass().isAssignableFrom(dest.getClass())) {
throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() +
"] must be same or subclass as source class [" + src.getClass().getName() + "]");
diff --git a/spring-core/src/main/java/org/springframework/util/TypeUtils.java b/spring-core/src/main/java/org/springframework/util/TypeUtils.java
index 4ec7deb1154..ddcd42723e9 100644
--- a/spring-core/src/main/java/org/springframework/util/TypeUtils.java
+++ b/spring-core/src/main/java/org/springframework/util/TypeUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -215,7 +215,6 @@ public abstract class TypeUtils {
if (rhsType == null) {
return true;
}
-
if (lhsType == null) {
return false;
}
diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java b/spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java
index 2a36c9e6042..a07dca88a25 100644
--- a/spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java
+++ b/spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -49,7 +49,7 @@ public abstract class FutureAdapter implements Future {
* @param adaptee the future to delegate to
*/
protected FutureAdapter(Future adaptee) {
- Assert.notNull(adaptee, "'delegate' must not be null");
+ Assert.notNull(adaptee, "Delegate must not be null");
this.adaptee = adaptee;
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/AccessException.java b/spring-expression/src/main/java/org/springframework/expression/AccessException.java
index 23c1e57888d..74ee5c3c37a 100644
--- a/spring-expression/src/main/java/org/springframework/expression/AccessException.java
+++ b/spring-expression/src/main/java/org/springframework/expression/AccessException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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,6 +25,14 @@ package org.springframework.expression;
@SuppressWarnings("serial")
public class AccessException extends Exception {
+ /**
+ * Create an AccessException with a specific message.
+ * @param message the message
+ */
+ public AccessException(String message) {
+ super(message);
+ }
+
/**
* Create an AccessException with a specific message and cause.
* @param message the message
@@ -34,12 +42,4 @@ public class AccessException extends Exception {
super(message, cause);
}
- /**
- * Create an AccessException with a specific message.
- * @param message the message
- */
- public AccessException(String message) {
- super(message);
- }
-
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/ConstructorExecutor.java b/spring-expression/src/main/java/org/springframework/expression/ConstructorExecutor.java
index 71efb3039aa..8352b2ff2a6 100644
--- a/spring-expression/src/main/java/org/springframework/expression/ConstructorExecutor.java
+++ b/spring-expression/src/main/java/org/springframework/expression/ConstructorExecutor.java
@@ -36,13 +36,12 @@ public interface ConstructorExecutor {
/**
* Execute a constructor in the specified context using the specified arguments.
- *
* @param context the evaluation context in which the command is being executed
- * @param arguments the arguments to the constructor call, should match (in terms of
- * number and type) whatever the command will need to run
+ * @param arguments the arguments to the constructor call, should match (in terms
+ * of number and type) whatever the command will need to run
* @return the new object
* @throws AccessException if there is a problem executing the command or the
- * CommandExecutor is no longer valid
+ * CommandExecutor is no longer valid
*/
TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException;
diff --git a/spring-expression/src/main/java/org/springframework/expression/OperatorOverloader.java b/spring-expression/src/main/java/org/springframework/expression/OperatorOverloader.java
index 7291575c9cb..da298b40e33 100644
--- a/spring-expression/src/main/java/org/springframework/expression/OperatorOverloader.java
+++ b/spring-expression/src/main/java/org/springframework/expression/OperatorOverloader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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,9 +17,9 @@
package org.springframework.expression;
/**
- * By default the mathematical operators {@link Operation} support simple types like
- * numbers. By providing an implementation of OperatorOverloader, a user of the expression
- * language can support these operations on other types.
+ * By default the mathematical operators {@link Operation} support simple types
+ * like numbers. By providing an implementation of OperatorOverloader, a user
+ * of the expression language can support these operations on other types.
*
* @author Andy Clement
* @since 3.0
@@ -27,21 +27,21 @@ package org.springframework.expression;
public interface OperatorOverloader {
/**
- * Return true if the operator overloader supports the specified operation between the
- * two operands and so should be invoked to handle it.
+ * Return true if the operator overloader supports the specified operation
+ * between the two operands and so should be invoked to handle it.
* @param operation the operation to be performed
* @param leftOperand the left operand
* @param rightOperand the right operand
- * @return true if the OperatorOverloader supports the specified operation between the
- * two operands
+ * @return true if the OperatorOverloader supports the specified operation
+ * between the two operands
* @throws EvaluationException if there is a problem performing the operation
*/
boolean overridesOperation(Operation operation, Object leftOperand, Object rightOperand)
throws EvaluationException;
/**
- * Execute the specified operation on two operands, returning a result. See
- * {@link Operation} for supported operations.
+ * Execute the specified operation on two operands, returning a result.
+ * See {@link Operation} for supported operations.
* @param operation the operation to be performed
* @param leftOperand the left operand
* @param rightOperand the right operand
diff --git a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java
index 1eb6e89df37..394348a12c6 100644
--- a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java
+++ b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java
@@ -112,6 +112,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
String prefix = context.getExpressionPrefix();
String suffix = context.getExpressionSuffix();
int startIdx = 0;
+
while (startIdx < expressionString.length()) {
int prefixIndex = expressionString.indexOf(prefix, startIdx);
if (prefixIndex >= startIdx) {
@@ -126,22 +127,18 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
"No ending suffix '" + suffix + "' for expression starting at character " +
prefixIndex + ": " + expressionString.substring(prefixIndex));
}
-
if (suffixIndex == afterPrefixIndex) {
throw new ParseException(expressionString, prefixIndex,
"No expression defined within delimiter '" + prefix + suffix +
"' at character " + prefixIndex);
}
-
String expr = expressionString.substring(prefixIndex + prefix.length(), suffixIndex);
expr = expr.trim();
-
if (expr.isEmpty()) {
throw new ParseException(expressionString, prefixIndex,
"No expression defined within delimiter '" + prefix + suffix +
"' at character " + prefixIndex);
}
-
expressions.add(doParseExpression(expr, context));
startIdx = suffixIndex + suffix.length();
}
@@ -151,6 +148,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
startIdx = expressionString.length();
}
}
+
return expressions.toArray(new Expression[expressions.size()]);
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java b/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java
index 0b1ee9964b5..4bc180f498e 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -32,6 +32,7 @@ import org.springframework.expression.TypeComparator;
import org.springframework.expression.TypeConverter;
import org.springframework.expression.TypedValue;
import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
/**
* An ExpressionState is for maintaining per-expression-evaluation state, any changes to
@@ -53,6 +54,12 @@ public class ExpressionState {
private final TypedValue rootObject;
+ private final SpelParserConfiguration configuration;
+
+ private Stack contextObjects;
+
+ private Stack variableScopes;
+
// When entering a new scope there is a new base object which should be used
// for '#this' references (or to act as a target for unqualified references).
// This stack captures those objects at each nested scope level.
@@ -62,12 +69,6 @@ public class ExpressionState {
// element from list1
private Stack scopeRootObjects;
- private final SpelParserConfiguration configuration;
-
- private Stack variableScopes;
-
- private Stack contextObjects;
-
public ExpressionState(EvaluationContext context) {
this(context, context.getRootObject(), new SpelParserConfiguration(false, false));
@@ -105,7 +106,7 @@ public class ExpressionState {
* The active context object is what unqualified references to properties/etc are resolved against.
*/
public TypedValue getActiveContextObject() {
- if (this.contextObjects == null || this.contextObjects.isEmpty()) {
+ if (CollectionUtils.isEmpty(this.contextObjects)) {
return this.rootObject;
}
return this.contextObjects.peek();
@@ -130,7 +131,7 @@ public class ExpressionState {
}
public TypedValue getScopeRootContextObject() {
- if (this.scopeRootObjects == null || this.scopeRootObjects.isEmpty()) {
+ if (CollectionUtils.isEmpty(this.scopeRootObjects)) {
return this.rootObject;
}
return this.scopeRootObjects.peek();
@@ -142,12 +143,7 @@ public class ExpressionState {
public TypedValue lookupVariable(String name) {
Object value = this.relatedContext.lookupVariable(name);
- if (value == null) {
- return TypedValue.NULL;
- }
- else {
- return new TypedValue(value);
- }
+ return (value != null ? new TypedValue(value) : TypedValue.NULL);
}
public TypeComparator getTypeComparator() {
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java b/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java
index bb3336746f9..15c308b5ec4 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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,6 @@ package org.springframework.expression.spel;
import org.springframework.core.SpringProperties;
-
/**
* Configuration object for the SpEL expression parser.
*
@@ -106,35 +105,35 @@ public class SpelParserConfiguration {
/**
- * @return the configuration mode for parsers using this configuration object
+ * Return the configuration mode for parsers using this configuration object.
*/
public SpelCompilerMode getCompilerMode() {
return this.compilerMode;
}
/**
- * @return the ClassLoader to use as the basis for expression compilation
+ * Return the ClassLoader to use as the basis for expression compilation.
*/
public ClassLoader getCompilerClassLoader() {
return this.compilerClassLoader;
}
/**
- * @return {@code true} if {@code null} references should be automatically grown
+ * Return {@code true} if {@code null} references should be automatically grown.
*/
public boolean isAutoGrowNullReferences() {
return this.autoGrowNullReferences;
}
/**
- * @return {@code true} if collections should be automatically grown
+ * Return {@code true} if collections should be automatically grown.
*/
public boolean isAutoGrowCollections() {
return this.autoGrowCollections;
}
/**
- * @return the maximum size that a collection can auto grow
+ * Return the maximum size that a collection can auto grow.
*/
public int getMaximumAutoGrowSize() {
return this.maximumAutoGrowSize;
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/BeanReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/BeanReference.java
index 67021482708..545f865d97b 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/BeanReference.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/BeanReference.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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,7 +37,7 @@ public class BeanReference extends SpelNodeImpl {
private final String beanName;
- public BeanReference(int pos,String beanName) {
+ public BeanReference(int pos, String beanName) {
super(pos);
this.beanName = beanName;
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/CompoundExpression.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/CompoundExpression.java
index 6d739ed30c8..26c17fb084e 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/CompoundExpression.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/CompoundExpression.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -31,7 +31,7 @@ import org.springframework.expression.spel.SpelEvaluationException;
*/
public class CompoundExpression extends SpelNodeImpl {
- public CompoundExpression(int pos,SpelNodeImpl... expressionComponents) {
+ public CompoundExpression(int pos, SpelNodeImpl... expressionComponents) {
super(pos, expressionComponents);
if (expressionComponents.length < 2) {
throw new IllegalStateException("Do not build compound expressions with less than two entries: " +
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
index 81c9f031d45..e4823caa6a5 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -59,7 +59,7 @@ public class FunctionReference extends SpelNodeImpl {
public FunctionReference(String functionName, int pos, SpelNodeImpl... arguments) {
- super(pos,arguments);
+ super(pos, arguments);
this.name = functionName;
}
@@ -107,15 +107,15 @@ public class FunctionReference extends SpelNodeImpl {
SpelMessage.FUNCTION_MUST_BE_STATIC, ClassUtils.getQualifiedMethodName(method), this.name);
}
- argumentConversionOccurred = false;
+ this.argumentConversionOccurred = false;
// Convert arguments if necessary and remap them for varargs if required
if (functionArgs != null) {
TypeConverter converter = state.getEvaluationContext().getTypeConverter();
- argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method);
+ this.argumentConversionOccurred = ReflectionHelper.convertAllArguments(converter, functionArgs, method);
}
if (method.isVarArgs()) {
- functionArgs =
- ReflectionHelper.setupArgumentsForVarargsInvocation(method.getParameterTypes(), functionArgs);
+ functionArgs = ReflectionHelper.setupArgumentsForVarargsInvocation(
+ method.getParameterTypes(), functionArgs);
}
try {
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java
index 32a837eaa9c..91618db73ed 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -51,7 +51,7 @@ import org.springframework.expression.spel.support.ReflectivePropertyAccessor;
// TODO support correct syntax for multidimensional [][][] and not [,,,]
public class Indexer extends SpelNodeImpl {
- private static enum IndexedType {ARRAY, LIST, MAP, STRING, OBJECT}
+ private enum IndexedType {ARRAY, LIST, MAP, STRING, OBJECT}
// These fields are used when the indexer is being used as a property read accessor.
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/NullLiteral.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/NullLiteral.java
index c766e757ff0..87dcf4f834b 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/NullLiteral.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/NullLiteral.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -29,7 +29,7 @@ import org.springframework.expression.spel.CodeFlow;
public class NullLiteral extends Literal {
public NullLiteral(int pos) {
- super(null,pos);
+ super(null, pos);
this.exitTypeDescriptor = "Ljava/lang/Object";
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java
index e46391f891d..bbd8ff20b55 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -44,7 +44,7 @@ public class OpAnd extends Operator {
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
- if (getBooleanValue(state, getLeftOperand()) == false) {
+ if (!getBooleanValue(state, getLeftOperand())) {
// no need to evaluate right operand
return BooleanTypedValue.FALSE;
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java
index 1fc99b21280..ae33e8dd1a5 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java
@@ -192,8 +192,8 @@ public class OpPlus extends Operator {
private void walk(MethodVisitor mv, CodeFlow cf, SpelNodeImpl operand) {
if (operand instanceof OpPlus) {
OpPlus plus = (OpPlus)operand;
- walk(mv,cf,plus.getLeftOperand());
- walk(mv,cf,plus.getRightOperand());
+ walk(mv, cf, plus.getLeftOperand());
+ walk(mv, cf, plus.getRightOperand());
}
else {
cf.enterCompilationScope();
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java
index f033519e5af..387259094b1 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Operator.java
@@ -87,7 +87,7 @@ public abstract class Operator extends SpelNodeImpl {
protected boolean isCompilableOperatorUsingNumerics() {
SpelNodeImpl left = getLeftOperand();
- SpelNodeImpl right= getRightOperand();
+ SpelNodeImpl right = getRightOperand();
if (!left.isCompilable() || !right.isCompilable()) {
return false;
}
@@ -273,11 +273,11 @@ public abstract class Operator extends SpelNodeImpl {
boolean rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
// If the declared descriptors aren't providing the information, try the actual descriptors
- if (!leftNumeric && !ld.equals(leftActualDescriptor)) {
+ if (!leftNumeric && !ObjectUtils.nullSafeEquals(ld, leftActualDescriptor)) {
ld = leftActualDescriptor;
leftNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
}
- if (!rightNumeric && !rd.equals(rightActualDescriptor)) {
+ if (!rightNumeric && !ObjectUtils.nullSafeEquals(rd, rightActualDescriptor)) {
rd = rightActualDescriptor;
rightNumeric = CodeFlow.isPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java
index 60767cd5e2f..87062b240f0 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java
index f5a88679ad7..4e88e5bf2db 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -77,6 +77,7 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
}
+ @Deprecated
protected SpelNodeImpl getPreviousChild() {
SpelNodeImpl result = null;
if (this.parent != null) {
@@ -214,9 +215,9 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
/**
- * Generate code that handles building the argument values for the specified method. This method will take account
- * of whether the invoked method is a varargs method and if it is then the argument values will be appropriately
- * packaged into an array.
+ * Generate code that handles building the argument values for the specified method.
+ * This method will take account of whether the invoked method is a varargs method
+ * and if it is then the argument values will be appropriately packaged into an array.
* @param mv the method visitor where code should be generated
* @param cf the current codeflow
* @param member the method or constructor for which arguments are being setup
@@ -226,7 +227,7 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
String[] paramDescriptors = null;
boolean isVarargs = false;
if (member instanceof Constructor) {
- Constructor> ctor = (Constructor>)member;
+ Constructor> ctor = (Constructor>) member;
paramDescriptors = CodeFlow.toDescriptors(ctor.getParameterTypes());
isVarargs = ctor.isVarArgs();
}
@@ -246,25 +247,25 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
generateCodeForArgument(mv, cf, arguments[p], paramDescriptors[p]);
}
- SpelNodeImpl lastchild = (childCount == 0 ? null : arguments[childCount - 1]);
- String arraytype = paramDescriptors[paramDescriptors.length - 1];
+ SpelNodeImpl lastChild = (childCount == 0 ? null : arguments[childCount - 1]);
+ String arrayType = paramDescriptors[paramDescriptors.length - 1];
// Determine if the final passed argument is already suitably packaged in array
// form to be passed to the method
- if (lastchild != null && lastchild.getExitDescriptor().equals(arraytype)) {
- generateCodeForArgument(mv, cf, lastchild, paramDescriptors[p]);
+ if (lastChild != null && arrayType.equals(lastChild.getExitDescriptor())) {
+ generateCodeForArgument(mv, cf, lastChild, paramDescriptors[p]);
}
else {
- arraytype = arraytype.substring(1); // trim the leading '[', may leave other '['
+ arrayType = arrayType.substring(1); // trim the leading '[', may leave other '['
// build array big enough to hold remaining arguments
- CodeFlow.insertNewArrayCode(mv, childCount - p, arraytype);
+ CodeFlow.insertNewArrayCode(mv, childCount - p, arrayType);
// Package up the remaining arguments into the array
int arrayindex = 0;
while (p < childCount) {
SpelNodeImpl child = arguments[p];
mv.visitInsn(DUP);
CodeFlow.insertOptimalLoad(mv, arrayindex++);
- generateCodeForArgument(mv, cf, child, arraytype);
- CodeFlow.insertArrayStore(mv, arraytype);
+ generateCodeForArgument(mv, cf, child, arrayType);
+ CodeFlow.insertArrayStore(mv, arrayType);
p++;
}
}
@@ -283,15 +284,16 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes {
protected static void generateCodeForArgument(MethodVisitor mv, CodeFlow cf, SpelNodeImpl argument, String paramDesc) {
cf.enterCompilationScope();
argument.generateCode(mv, cf);
- boolean primitiveOnStack = CodeFlow.isPrimitive(cf.lastDescriptor());
+ String lastDesc = cf.lastDescriptor();
+ boolean primitiveOnStack = CodeFlow.isPrimitive(lastDesc);
// Check if need to box it for the method reference?
if (primitiveOnStack && paramDesc.charAt(0) == 'L') {
- CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
+ CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));
}
else if (paramDesc.length() == 1 && !primitiveOnStack) {
- CodeFlow.insertUnboxInsns(mv, paramDesc.charAt(0), cf.lastDescriptor());
+ CodeFlow.insertUnboxInsns(mv, paramDesc.charAt(0), lastDesc);
}
- else if (!cf.lastDescriptor().equals(paramDesc)) {
+ else if (!paramDesc.equals(lastDesc)) {
// This would be unnecessary in the case of subtyping (e.g. method takes Number but Integer passed in)
CodeFlow.insertCheckCast(mv, paramDesc);
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java
index faa14f3d42b..dff1966e31b 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -88,14 +88,13 @@ public class SpelCompiler implements Opcodes {
/**
- * Attempt compilation of the supplied expression. A check is
- * made to see if it is compilable before compilation proceeds. The
- * check involves visiting all the nodes in the expression Ast and
- * ensuring enough state is known about them that bytecode can
- * be generated for them.
+ * Attempt compilation of the supplied expression. A check is made to see
+ * if it is compilable before compilation proceeds. The check involves
+ * visiting all the nodes in the expression Ast and ensuring enough state
+ * is known about them that bytecode can be generated for them.
* @param expression the expression to compile
- * @return an instance of the class implementing the compiled expression, or null
- * if compilation is not possible
+ * @return an instance of the class implementing the compiled expression,
+ * or {@code null} if compilation is not possible
*/
public CompiledExpression compile(SpelNodeImpl expression) {
if (expression.isCompilable()) {
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
index 248eb45397a..f40a1883e8e 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -27,6 +27,7 @@ import org.springframework.expression.TypeConverter;
import org.springframework.expression.spel.SpelEvaluationException;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
+import org.springframework.util.CollectionUtils;
import org.springframework.util.MethodInvoker;
/**
@@ -141,8 +142,8 @@ public class ReflectionHelper {
static ArgumentsMatchInfo compareArgumentsVarargs(
List expectedArgTypes, List suppliedArgTypes, TypeConverter typeConverter) {
- Assert.isTrue(expectedArgTypes != null && expectedArgTypes.size() > 0,
- "Expected arguments must at least include one array (the vargargs parameter)");
+ Assert.isTrue(!CollectionUtils.isEmpty(expectedArgTypes),
+ "Expected arguments must at least include one array (the varargs parameter)");
Assert.isTrue(expectedArgTypes.get(expectedArgTypes.size() - 1).isArray(),
"Final expected argument should be array type (the varargs parameter)");
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java
index b2798c3ddab..c31ae8be57b 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodExecutor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -44,6 +44,7 @@ public class ReflectiveMethodExecutor implements MethodExecutor {
private boolean argumentConversionOccurred = false;
+
public ReflectiveMethodExecutor(Method method) {
this.method = method;
if (method.isVarArgs()) {
@@ -55,6 +56,7 @@ public class ReflectiveMethodExecutor implements MethodExecutor {
}
}
+
public Method getMethod() {
return this.method;
}
@@ -68,8 +70,8 @@ public class ReflectiveMethodExecutor implements MethodExecutor {
* method (if there is one!). For toString() it may walk as far as Object.
*/
public Class> getPublicDeclaringClass() {
- if (!computedPublicDeclaringClass) {
- this.publicDeclaringClass = discoverPublicClass(method, method.getDeclaringClass());
+ if (!this.computedPublicDeclaringClass) {
+ this.publicDeclaringClass = discoverPublicClass(this.method, this.method.getDeclaringClass());
this.computedPublicDeclaringClass = true;
}
return this.publicDeclaringClass;
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
index 5efc4456160..6e95e7941de 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -93,14 +93,23 @@ public class StandardEvaluationContext implements EvaluationContext {
return this.rootObject;
}
- public void addConstructorResolver(ConstructorResolver resolver) {
- ensureConstructorResolversInitialized();
- this.constructorResolvers.add(this.constructorResolvers.size() - 1, resolver);
+ public void setPropertyAccessors(List propertyAccessors) {
+ this.propertyAccessors = propertyAccessors;
}
- public boolean removeConstructorResolver(ConstructorResolver resolver) {
- ensureConstructorResolversInitialized();
- return this.constructorResolvers.remove(resolver);
+ @Override
+ public List getPropertyAccessors() {
+ ensurePropertyAccessorsInitialized();
+ return this.propertyAccessors;
+ }
+
+ public void addPropertyAccessor(PropertyAccessor accessor) {
+ ensurePropertyAccessorsInitialized();
+ this.propertyAccessors.add(this.propertyAccessors.size() - 1, accessor);
+ }
+
+ public boolean removePropertyAccessor(PropertyAccessor accessor) {
+ return this.propertyAccessors.remove(accessor);
}
public void setConstructorResolvers(List constructorResolvers) {
@@ -113,14 +122,14 @@ public class StandardEvaluationContext implements EvaluationContext {
return this.constructorResolvers;
}
- public void addMethodResolver(MethodResolver resolver) {
- ensureMethodResolversInitialized();
- this.methodResolvers.add(this.methodResolvers.size() - 1, resolver);
+ public void addConstructorResolver(ConstructorResolver resolver) {
+ ensureConstructorResolversInitialized();
+ this.constructorResolvers.add(this.constructorResolvers.size() - 1, resolver);
}
- public boolean removeMethodResolver(MethodResolver methodResolver) {
- ensureMethodResolversInitialized();
- return this.methodResolvers.remove(methodResolver);
+ public boolean removeConstructorResolver(ConstructorResolver resolver) {
+ ensureConstructorResolversInitialized();
+ return this.constructorResolvers.remove(resolver);
}
public void setMethodResolvers(List methodResolvers) {
@@ -133,6 +142,16 @@ public class StandardEvaluationContext implements EvaluationContext {
return this.methodResolvers;
}
+ public void addMethodResolver(MethodResolver resolver) {
+ ensureMethodResolversInitialized();
+ this.methodResolvers.add(this.methodResolvers.size() - 1, resolver);
+ }
+
+ public boolean removeMethodResolver(MethodResolver methodResolver) {
+ ensureMethodResolversInitialized();
+ return this.methodResolvers.remove(methodResolver);
+ }
+
public void setBeanResolver(BeanResolver beanResolver) {
this.beanResolver = beanResolver;
}
@@ -142,25 +161,6 @@ public class StandardEvaluationContext implements EvaluationContext {
return this.beanResolver;
}
- public void addPropertyAccessor(PropertyAccessor accessor) {
- ensurePropertyAccessorsInitialized();
- this.propertyAccessors.add(this.propertyAccessors.size() - 1, accessor);
- }
-
- public boolean removePropertyAccessor(PropertyAccessor accessor) {
- return this.propertyAccessors.remove(accessor);
- }
-
- public void setPropertyAccessors(List propertyAccessors) {
- this.propertyAccessors = propertyAccessors;
- }
-
- @Override
- public List getPropertyAccessors() {
- ensurePropertyAccessorsInitialized();
- return this.propertyAccessors;
- }
-
public void setTypeLocator(TypeLocator typeLocator) {
Assert.notNull(typeLocator, "TypeLocator must not be null");
this.typeLocator = typeLocator;
@@ -169,7 +169,7 @@ public class StandardEvaluationContext implements EvaluationContext {
@Override
public TypeLocator getTypeLocator() {
if (this.typeLocator == null) {
- this.typeLocator = new StandardTypeLocator();
+ this.typeLocator = new StandardTypeLocator();
}
return this.typeLocator;
}
@@ -244,6 +244,7 @@ public class StandardEvaluationContext implements EvaluationContext {
}
}
+
private void ensurePropertyAccessorsInitialized() {
if (this.propertyAccessors == null) {
initializePropertyAccessors();
@@ -258,6 +259,20 @@ public class StandardEvaluationContext implements EvaluationContext {
}
}
+ private void ensureConstructorResolversInitialized() {
+ if (this.constructorResolvers == null) {
+ initializeConstructorResolvers();
+ }
+ }
+
+ private synchronized void initializeConstructorResolvers() {
+ if (this.constructorResolvers == null) {
+ List defaultResolvers = new ArrayList();
+ defaultResolvers.add(new ReflectiveConstructorResolver());
+ this.constructorResolvers = defaultResolvers;
+ }
+ }
+
private void ensureMethodResolversInitialized() {
if (this.methodResolvers == null) {
initializeMethodResolvers();
@@ -273,18 +288,4 @@ public class StandardEvaluationContext implements EvaluationContext {
}
}
- private void ensureConstructorResolversInitialized() {
- if (this.constructorResolvers == null) {
- initializeConstructorResolvers();
- }
- }
-
- private synchronized void initializeConstructorResolvers() {
- if (this.constructorResolvers == null) {
- List defaultResolvers = new ArrayList();
- defaultResolvers.add(new ReflectiveConstructorResolver());
- this.constructorResolvers = defaultResolvers;
- }
- }
-
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
index 6243c2d7542..40cfe8c2f0e 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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,8 +67,9 @@ public class StandardTypeConverter implements TypeConverter {
return this.conversionService.convert(value, sourceType, targetType);
}
catch (ConversionException ex) {
- throw new SpelEvaluationException(
- ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
+ throw new SpelEvaluationException(ex, SpelMessage.TYPE_CONVERSION_ERROR,
+ (sourceType != null ? sourceType.toString() : (value != null ? value.getClass().getName() : "null")),
+ targetType.toString());
}
}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java
index be8e4905463..98dfd8c5cc6 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java
@@ -408,7 +408,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
// Apply kept transaction settings, if any.
if (this.readOnly) {
try {
- this.target.setReadOnly(this.readOnly);
+ this.target.setReadOnly(true);
}
catch (Exception ex) {
// "read-only not supported" -> ignore, it's just a hint anyway
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java
index 513a9c6085f..d6422adb916 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ResourceDatabasePopulator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -153,7 +153,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
* @see #addScript(Resource)
*/
public void setSqlScriptEncoding(String sqlScriptEncoding) {
- this.sqlScriptEncoding = StringUtils.hasText(sqlScriptEncoding) ? sqlScriptEncoding : null;
+ this.sqlScriptEncoding = (StringUtils.hasText(sqlScriptEncoding) ? sqlScriptEncoding : null);
}
/**
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/ContentTypeResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/ContentTypeResolver.java
index f9fe42fe6e8..6e179407c6b 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/converter/ContentTypeResolver.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/ContentTypeResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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,6 +17,7 @@
package org.springframework.messaging.converter;
import org.springframework.messaging.MessageHeaders;
+import org.springframework.util.InvalidMimeTypeException;
import org.springframework.util.MimeType;
/**
@@ -29,15 +30,11 @@ public interface ContentTypeResolver {
/**
* Determine the {@link MimeType} of a message from the given MessageHeaders.
- *
* @param headers the headers to use for the resolution
- * @return the resolved {@code MimeType} of {@code null} if none found
- *
- * @throws org.springframework.util.InvalidMimeTypeException if the content type
- * is a String that cannot be parsed
- * @throws java.lang.IllegalArgumentException if there is a content type but
- * its type is unknown
+ * @return the resolved {@code MimeType}, or {@code null} if none found
+ * @throws InvalidMimeTypeException if the content type is a String that cannot be parsed
+ * @throws IllegalArgumentException if there is a content type but its type is unknown
*/
- MimeType resolve(MessageHeaders headers);
+ MimeType resolve(MessageHeaders headers) throws InvalidMimeTypeException;
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/MarshallingMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/MarshallingMessageConverter.java
index 965af158804..2606238e5c7 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/converter/MarshallingMessageConverter.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/MarshallingMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -175,7 +175,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter {
payload = writer.toString();
}
}
- catch (Exception ex) {
+ catch (Throwable ex) {
throw new MessageConversionException("Could not marshal XML: " + ex.getMessage(), ex);
}
return payload;
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java
index 058f05a44e8..4a79beef4e7 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -190,6 +190,9 @@ public class DestinationPatternsMessageCondition extends AbstractMessageConditio
@Override
public int compareTo(DestinationPatternsMessageCondition other, Message> message) {
String destination = (String) message.getHeaders().get(LOOKUP_DESTINATION_HEADER);
+ if (destination == null) {
+ return 0;
+ }
Comparator patternComparator = this.pathMatcher.getPatternComparator(destination);
Iterator iterator = patterns.iterator();
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java
index 0103450e52b..a6ca23683e4 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java
@@ -38,11 +38,14 @@ import org.springframework.util.ClassUtils;
*/
public abstract class AbstractExceptionHandlerMethodResolver {
- private static final Method NO_METHOD_FOUND = ClassUtils.getMethodIfAvailable(System.class, "currentTimeMillis");
+ private static final Method NO_METHOD_FOUND =
+ ClassUtils.getMethodIfAvailable(System.class, "currentTimeMillis");
- private final Map, Method> mappedMethods = new ConcurrentHashMap, Method>(16);
+ private final Map, Method> mappedMethods =
+ new ConcurrentHashMap, Method>(16);
- private final Map, Method> exceptionLookupCache = new ConcurrentHashMap, Method>(16);
+ private final Map, Method> exceptionLookupCache =
+ new ConcurrentHashMap, Method>(16);
/**
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandler.java
index 20e30a48343..53894c1fa80 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandler.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -40,13 +40,13 @@ public interface HandlerMethodReturnValueHandler {
/**
* Handle the given return value.
* @param returnValue the value returned from the handler method
- * @param returnType the type of the return value. This type must have
- * previously been passed to
- * {@link #supportsReturnType(org.springframework.core.MethodParameter)}
- * and it must have returned {@code true}
+ * @param returnType the type of the return value. This type must have previously
+ * been passed to {@link #supportsReturnType(org.springframework.core.MethodParameter)}
+ * and it must have returned {@code true}.
* @param message the message that caused this method to be called
* @throws Exception if the return value handling results in an error
*/
- void handleReturnValue(Object returnValue, MethodParameter returnType, Message> message) throws Exception;
+ void handleReturnValue(Object returnValue, MethodParameter returnType, Message> message)
+ throws Exception;
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributesContextHolder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributesContextHolder.java
index b7136e96600..ed340939006 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributesContextHolder.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpAttributesContextHolder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -19,7 +19,6 @@ package org.springframework.messaging.simp;
import org.springframework.core.NamedThreadLocal;
import org.springframework.messaging.Message;
-
/**
* Holder class to expose SiMP attributes associated with a session (e.g. WebSocket)
* in the form of a thread-bound {@link SimpAttributes} object.
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpSessionScope.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpSessionScope.java
index ebe85a35849..d3cda542dbe 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpSessionScope.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpSessionScope.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -34,17 +34,17 @@ public class SimpSessionScope implements Scope {
@Override
public Object get(String name, ObjectFactory> objectFactory) {
SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes();
- Object value = simpAttributes.getAttribute(name);
- if (value != null) {
- return value;
+ Object scopedObject = simpAttributes.getAttribute(name);
+ if (scopedObject != null) {
+ return scopedObject;
}
synchronized (simpAttributes.getSessionMutex()) {
- value = simpAttributes.getAttribute(name);
- if (value == null) {
- value = objectFactory.getObject();
- simpAttributes.setAttribute(name, value);
+ scopedObject = simpAttributes.getAttribute(name);
+ if (scopedObject == null) {
+ scopedObject = objectFactory.getObject();
+ simpAttributes.setAttribute(name, scopedObject);
}
- return value;
+ return scopedObject;
}
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java
index 5268d925a14..b39a01643c9 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -72,7 +72,7 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH
public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired) {
- Assert.notNull(messagingTemplate, "messagingTemplate must not be null");
+ Assert.notNull(messagingTemplate, "'messagingTemplate' must not be null");
this.messagingTemplate = messagingTemplate;
this.annotationRequired = annotationRequired;
}
@@ -124,7 +124,7 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH
}
/**
- * @return the configured header initializer.
+ * Return the configured header initializer.
*/
public MessageHeaderInitializer getHeaderInitializer() {
return this.headerInitializer;
@@ -141,7 +141,9 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH
}
@Override
- public void handleReturnValue(Object returnValue, MethodParameter returnType, Message> message) throws Exception {
+ public void handleReturnValue(Object returnValue, MethodParameter returnType, Message> message)
+ throws Exception {
+
if (returnValue == null) {
return;
}
@@ -151,7 +153,7 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH
PlaceholderResolver varResolver = initVarResolver(headers);
Object annotation = findAnnotation(returnType);
- if (annotation != null && annotation instanceof SendToUser) {
+ if (annotation instanceof SendToUser) {
SendToUser sendToUser = (SendToUser) annotation;
boolean broadcast = sendToUser.broadcast();
String user = getUserName(message, headers);
@@ -176,7 +178,7 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH
}
}
else {
- SendTo sendTo = (SendTo) annotation;
+ SendTo sendTo = (SendTo) annotation; // possibly null
String[] destinations = getTargetDestinations(sendTo, message, this.defaultDestinationPrefix);
for (String destination : destinations) {
destination = this.placeholderHelper.replacePlaceholders(destination, varResolver);
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java
index e18af8df8b4..668112670aa 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -109,12 +109,12 @@ public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturn
}
MessageHeaders headers = message.getHeaders();
- String destination = SimpMessageHeaderAccessor.getDestination(headers);
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers);
String subscriptionId = SimpMessageHeaderAccessor.getSubscriptionId(headers);
+ String destination = SimpMessageHeaderAccessor.getDestination(headers);
if (subscriptionId == null) {
- throw new IllegalStateException("No subscriptionId in " + message +
+ throw new IllegalStateException("No subscription id in " + message +
" returned by: " + returnType.getMethod());
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java
index 1d914cb0079..af7690661d0 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -105,7 +105,7 @@ public abstract class AbstractBrokerMessageHandler
this.clientOutboundChannel = outboundChannel;
this.brokerChannel = brokerChannel;
- destinationPrefixes = (destinationPrefixes != null) ? destinationPrefixes : Collections.emptyList();
+ destinationPrefixes = (destinationPrefixes != null ? destinationPrefixes : Collections.emptyList());
this.destinationPrefixes = Collections.unmodifiableCollection(destinationPrefixes);
}
@@ -242,7 +242,7 @@ public abstract class AbstractBrokerMessageHandler
protected boolean checkDestinationPrefix(String destination) {
- if ((destination == null) || CollectionUtils.isEmpty(this.destinationPrefixes)) {
+ if (destination == null || CollectionUtils.isEmpty(this.destinationPrefixes)) {
return true;
}
for (String prefix : this.destinationPrefixes) {
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java
index dfd5ba53dfe..ef3658302e2 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java
@@ -347,7 +347,9 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler {
getClientOutboundChannel().send(reply);
}
catch (Throwable ex) {
- logger.error("Failed to send " + message, ex);
+ if (logger.isErrorEnabled()) {
+ logger.error("Failed to send " + message, ex);
+ }
}
finally {
SessionInfo info = this.sessions.get(subscriptionEntry.getKey());
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java
index 7e27a9df072..0fe24cc687d 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java
@@ -268,8 +268,8 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
}
private void execute(Message message) {
- StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if (logger.isTraceEnabled()) {
+ StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
logger.trace("Sending " + accessor.getDetailedLogMessage(message.getPayload()));
}
TcpConnection conn = this.connection;
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java
index b1c48da3467..bb1d14e13e4 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java
@@ -75,7 +75,7 @@ public abstract class StompClientSupport {
/**
* Configure a scheduler to use for heartbeats and for receipt tracking.
- * Note: some transports have built-in support to work
+ *
Note: Some transports have built-in support to work
* with heartbeats and therefore do not require a TaskScheduler.
* Receipts however, if needed, do require a TaskScheduler to be configured.
*
By default, this is not set.
@@ -123,7 +123,8 @@ public abstract class StompClientSupport {
* is set to "0,0", and {@code true} otherwise.
*/
public boolean isDefaultHeartbeatEnabled() {
- return (getDefaultHeartbeat() != null && getDefaultHeartbeat()[0] != 0 && getDefaultHeartbeat()[1] != 0);
+ long[] heartbeat = getDefaultHeartbeat();
+ return (heartbeat[0] != 0 && heartbeat[1] != 0);
}
/**
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java
index c8f2f5eeae9..bc358a924d1 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -131,6 +131,7 @@ public interface StompSession {
void addReceiptLostTask(Runnable runnable);
}
+
/**
* A handle to use to unsubscribe or to track a receipt.
*/
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java
index 7e2d8503e63..a86f6df73fb 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserDestinationResult.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -39,8 +39,8 @@ public class UserDestinationResult {
private final String user;
- public UserDestinationResult(String sourceDestination,
- Set targetDestinations, String subscribeDestination, String user) {
+ public UserDestinationResult(String sourceDestination, Set targetDestinations,
+ String subscribeDestination, String user) {
Assert.notNull(sourceDestination, "'sourceDestination' must not be null");
Assert.notNull(targetDestinations, "'targetDestinations' must not be null");
@@ -93,9 +93,11 @@ public class UserDestinationResult {
return this.user;
}
+
@Override
public String toString() {
- return "UserDestinationResult[source=" + this.sourceDestination + ", target=" + this.targetDestinations +
+ return "UserDestinationResult [source=" + this.sourceDestination + ", target=" + this.targetDestinations +
", subscribeDestination=" + this.subscribeDestination + ", user=" + this.user + "]";
}
+
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java
index 983127cd84d..399260bec55 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -35,8 +35,7 @@ import org.springframework.util.Assert;
* application servers and periodically broadcasts the content of the local
* user registry.
*
- * The aggregated information
- * is maintained in a {@link MultiServerUserRegistry}.
+ * The aggregated information is maintained in a {@link MultiServerUserRegistry}.
*
* @author Rossen Stoyanchev
* @since 4.2
@@ -62,8 +61,8 @@ public class UserRegistryMessageHandler implements MessageHandler, ApplicationLi
* Constructor.
* @param userRegistry the registry with local and remote user registry information
* @param brokerTemplate template for broadcasting local registry information
- * @param broadcastDestination the destination to broadcast to
- * @param scheduler
+ * @param broadcastDestination the destination to broadcast to
+ * @param scheduler the task scheduler to use
*/
public UserRegistryMessageHandler(MultiServerUserRegistry userRegistry,
SimpMessagingTemplate brokerTemplate, String broadcastDestination, TaskScheduler scheduler) {
@@ -112,9 +111,12 @@ public class UserRegistryMessageHandler implements MessageHandler, ApplicationLi
long delay = getRegistryExpirationPeriod() / 2;
this.scheduledFuture = this.scheduler.scheduleWithFixedDelay(this.schedulerTask, delay);
}
- else if (this.scheduledFuture != null ){
- this.scheduledFuture.cancel(true);
- this.scheduledFuture = null;
+ else {
+ ScheduledFuture> future = this.scheduledFuture;
+ if (future != null ){
+ future.cancel(true);
+ this.scheduledFuture = null;
+ }
}
}
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java b/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java
index 45acbbf03fc..a03bbcf3025 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -152,9 +152,10 @@ public class ExecutorSubscribableChannel extends AbstractSubscribableChannel {
}
private Message> applyBeforeHandle(Message> message) {
+ Message> messageToUse = message;
for (ExecutorChannelInterceptor interceptor : executorInterceptors) {
- message = interceptor.beforeHandle(message, ExecutorSubscribableChannel.this, this.messageHandler);
- if (message == null) {
+ messageToUse = interceptor.beforeHandle(messageToUse, ExecutorSubscribableChannel.this, this.messageHandler);
+ if (messageToUse == null) {
String name = interceptor.getClass().getSimpleName();
if (logger.isDebugEnabled()) {
logger.debug(name + " returned null from beforeHandle, i.e. precluding the send.");
@@ -164,7 +165,7 @@ public class ExecutorSubscribableChannel extends AbstractSubscribableChannel {
}
this.interceptorIndex++;
}
- return message;
+ return messageToUse;
}
private void triggerAfterMessageHandled(Message> message, Exception ex) {
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java
index cbf1e361b7d..de182947ff4 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/support/MessageHeaderAccessor.java
@@ -578,7 +578,7 @@ public class MessageHeaderAccessor {
if (messageHeaders instanceof MutableMessageHeaders) {
MutableMessageHeaders mutableHeaders = (MutableMessageHeaders) messageHeaders;
MessageHeaderAccessor headerAccessor = mutableHeaders.getAccessor();
- if (requiredType.isAssignableFrom(headerAccessor.getClass())) {
+ if (requiredType == null || requiredType.isInstance(headerAccessor)) {
return (T) headerAccessor;
}
}
diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java
index 31f7ade1db8..ccbb9efe2f6 100644
--- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java
+++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -494,12 +494,14 @@ public abstract class EntityManagerFactoryUtils {
em.flush();
}
catch (RuntimeException ex) {
+ DataAccessException dae;
if (this.jpaDialect != null) {
- throw this.jpaDialect.translateExceptionIfPossible(ex);
+ dae = this.jpaDialect.translateExceptionIfPossible(ex);
}
else {
- throw convertJpaAccessExceptionIfPossible(ex);
+ dae = convertJpaAccessExceptionIfPossible(ex);
}
+ throw (dae != null ? dae : ex);
}
}
diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java b/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java
index efa71987472..fa6182c33c6 100644
--- a/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java
+++ b/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -33,9 +33,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
- *
Mock implementation of the {@link javax.servlet.FilterChain} interface. Used
- * for testing the web framework; also useful for testing custom
- * {@link javax.servlet.Filter} implementations.
+ * Mock implementation of the {@link javax.servlet.FilterChain} interface.
*
*
A {@link MockFilterChain} can be configured with one or more filters and a
* Servlet to invoke. The first time the chain is called, it invokes all filters
@@ -72,7 +70,6 @@ public class MockFilterChain implements FilterChain {
/**
* Create a FilterChain with a Servlet.
- *
* @param servlet the Servlet to invoke
* @since 3.2
*/
@@ -82,7 +79,6 @@ public class MockFilterChain implements FilterChain {
/**
* Create a {@code FilterChain} with Filter's and a Servlet.
- *
* @param servlet the {@link Servlet} to invoke in this {@link FilterChain}
* @param filters the {@link Filter}'s to invoke in this {@link FilterChain}
* @since 3.2
@@ -120,10 +116,7 @@ public class MockFilterChain implements FilterChain {
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
Assert.notNull(request, "Request must not be null");
Assert.notNull(response, "Response must not be null");
-
- if (this.request != null) {
- throw new IllegalStateException("This FilterChain has already been called!");
- }
+ Assert.state(this.request == null, "This FilterChain has already been called!");
if (this.iterator == null) {
this.iterator = this.filters.iterator();
diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockPageContext.java b/spring-test/src/main/java/org/springframework/mock/web/MockPageContext.java
index 1f7d18c23a2..079ec99740e 100644
--- a/spring-test/src/main/java/org/springframework/mock/web/MockPageContext.java
+++ b/spring-test/src/main/java/org/springframework/mock/web/MockPageContext.java
@@ -40,9 +40,7 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.jsp.PageContext} interface.
- *
- *
Used for testing the web framework; only necessary for testing
- * applications when testing custom JSP tags.
+ * Only necessary for testing applications when testing custom JSP tags.
*
*
Note: Expects initialization via the constructor rather than via the
* {@code PageContext.initialize} method. Does not support writing to a
diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContext.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContext.java
index 58225597d45..0b29c8df5b8 100644
--- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContext.java
+++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -55,6 +55,7 @@ class TransactionContext {
TransactionContext(TestContext testContext, PlatformTransactionManager transactionManager,
TransactionDefinition transactionDefinition, boolean defaultRollback) {
+
this.testContext = testContext;
this.transactionManager = transactionManager;
this.transactionDefinition = transactionDefinition;
@@ -62,6 +63,7 @@ class TransactionContext {
this.flaggedForRollback = defaultRollback;
}
+
TransactionStatus getTransactionStatus() {
return this.transactionStatus;
}
@@ -105,23 +107,22 @@ class TransactionContext {
}
/**
- * Immediately force a commit or rollback of the transaction
- * for the configured {@linkplain #getTestContext test context}, according to
- * the {@linkplain #isFlaggedForRollback rollback flag}.
+ * Immediately force a commit or rollback of the transaction for the
+ * configured test context, according to the {@linkplain #isFlaggedForRollback rollback flag}.
*/
void endTransaction() {
if (logger.isTraceEnabled()) {
logger.trace(String.format(
- "Ending transaction for test context %s; transaction status [%s]; rollback [%s]", this.testContext,
- this.transactionStatus, flaggedForRollback));
+ "Ending transaction for test context %s; transaction status [%s]; rollback [%s]",
+ this.testContext, this.transactionStatus, this.flaggedForRollback));
}
if (this.transactionStatus == null) {
throw new IllegalStateException(String.format(
- "Failed to end transaction for test context %s: transaction does not exist.", this.testContext));
+ "Failed to end transaction for test context %s: transaction does not exist.", this.testContext));
}
try {
- if (flaggedForRollback) {
+ if (this.flaggedForRollback) {
this.transactionManager.rollback(this.transactionStatus);
}
else {
@@ -133,8 +134,8 @@ class TransactionContext {
}
if (logger.isInfoEnabled()) {
- logger.info(String.format("%s transaction for test context %s.", (flaggedForRollback ? "Rolled back"
- : "Committed"), this.testContext));
+ logger.info(String.format("%s transaction for test context %s.",
+ (this.flaggedForRollback ? "Rolled back" : "Committed"), this.testContext));
}
}
diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContextHolder.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContextHolder.java
index 9f1a102d44c..6cc004ea974 100644
--- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContextHolder.java
+++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContextHolder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -26,18 +26,18 @@ import org.springframework.core.NamedInheritableThreadLocal;
*/
class TransactionContextHolder {
- private static final ThreadLocal currentTransactionContext = new NamedInheritableThreadLocal(
- "Test Transaction Context");
+ private static final ThreadLocal currentTransactionContext =
+ new NamedInheritableThreadLocal("Test Transaction Context");
- static TransactionContext getCurrentTransactionContext() {
- return currentTransactionContext.get();
- }
-
static void setCurrentTransactionContext(TransactionContext transactionContext) {
currentTransactionContext.set(transactionContext);
}
+ static TransactionContext getCurrentTransactionContext() {
+ return currentTransactionContext.get();
+ }
+
static TransactionContext removeCurrentTransactionContext() {
synchronized (currentTransactionContext) {
TransactionContext transactionContext = currentTransactionContext.get();
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/RequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/RequestBuilder.java
index c3f02ee2f37..c735da04551 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/RequestBuilder.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/RequestBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -34,7 +34,6 @@ public interface RequestBuilder {
/**
* Build the request.
- *
* @param servletContext the {@link ServletContext} to use to create the request
* @return the request
*/
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnection.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnection.java
index fd4ef702ba4..a0a9ad0aa52 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnection.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebConnection.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -85,8 +85,8 @@ public final class MockMvcWebConnection implements WebConnection {
* to {@link javax.servlet.http.HttpServletRequest#getContextPath()}
* which states that it can be an empty string and otherwise must start
* with a "/" character and not end with a "/" character.
- * @param mockMvc the {@code MockMvc} instance to use; never {@code null}
- * @param webClient the {@link WebClient} to use. never {@code null}
+ * @param mockMvc the {@code MockMvc} instance to use (never {@code null})
+ * @param webClient the {@link WebClient} to use (never {@code null})
* @param contextPath the contextPath to use
*/
public MockMvcWebConnection(MockMvc mockMvc, WebClient webClient, String contextPath) {
diff --git a/spring-tx/src/main/java/org/springframework/jca/cci/object/EisOperation.java b/spring-tx/src/main/java/org/springframework/jca/cci/object/EisOperation.java
index 19bd6dda704..c52ff6c82e9 100644
--- a/spring-tx/src/main/java/org/springframework/jca/cci/object/EisOperation.java
+++ b/spring-tx/src/main/java/org/springframework/jca/cci/object/EisOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -21,6 +21,7 @@ import javax.resource.cci.InteractionSpec;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jca.cci.core.CciTemplate;
+import org.springframework.util.Assert;
/**
* Base class for EIS operation objects that work with the CCI API.
@@ -47,9 +48,7 @@ public abstract class EisOperation implements InitializingBean {
* @see #setConnectionFactory
*/
public void setCciTemplate(CciTemplate cciTemplate) {
- if (cciTemplate == null) {
- throw new IllegalArgumentException("cciTemplate must not be null");
- }
+ Assert.notNull(cciTemplate, "CciTemplate must not be null");
this.cciTemplate = cciTemplate;
}
@@ -87,7 +86,7 @@ public abstract class EisOperation implements InitializingBean {
this.cciTemplate.afterPropertiesSet();
if (this.interactionSpec == null) {
- throw new IllegalArgumentException("interactionSpec is required");
+ throw new IllegalArgumentException("InteractionSpec is required");
}
}
diff --git a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java
index 6d1ebb8d597..b8cbf6d984b 100644
--- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java
+++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -50,6 +50,7 @@ import org.springframework.util.ObjectUtils;
* return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
* }
*
+ *
* Or, by using a builder accessible via static methods:
*
* @RequestMapping("/handle")
@@ -66,7 +67,7 @@ import org.springframework.util.ObjectUtils;
*/
public class ResponseEntity extends HttpEntity {
- private final Object statusCode;
+ private final Object status;
/**
@@ -104,7 +105,7 @@ public class ResponseEntity extends HttpEntity {
public ResponseEntity(T body, MultiValueMap headers, HttpStatus status) {
super(body, headers);
Assert.notNull(status, "HttpStatus must not be null");
- this.statusCode = status;
+ this.status = status;
}
/**
@@ -112,11 +113,11 @@ public class ResponseEntity extends HttpEntity {
* Just used behind the nested builder API.
* @param body the entity body
* @param headers the entity headers
- * @param statusCode the status code (as {@code HttpStatus} or as {@code Integer} value)
+ * @param status the status code (as {@code HttpStatus} or as {@code Integer} value)
*/
- private ResponseEntity(T body, MultiValueMap headers, Object statusCode) {
+ private ResponseEntity(T body, MultiValueMap headers, Object status) {
super(body, headers);
- this.statusCode = statusCode;
+ this.status = status;
}
@@ -125,11 +126,11 @@ public class ResponseEntity extends HttpEntity {
* @return the HTTP status as an HttpStatus enum entry
*/
public HttpStatus getStatusCode() {
- if (this.statusCode instanceof HttpStatus) {
- return (HttpStatus) this.statusCode;
+ if (this.status instanceof HttpStatus) {
+ return (HttpStatus) this.status;
}
else {
- return HttpStatus.valueOf((Integer) this.statusCode);
+ return HttpStatus.valueOf((Integer) this.status);
}
}
@@ -139,11 +140,11 @@ public class ResponseEntity extends HttpEntity {
* @since 4.3
*/
public int getStatusCodeValue() {
- if (this.statusCode instanceof HttpStatus) {
- return ((HttpStatus) this.statusCode).value();
+ if (this.status instanceof HttpStatus) {
+ return ((HttpStatus) this.status).value();
}
else {
- return (Integer) this.statusCode;
+ return (Integer) this.status;
}
}
@@ -157,21 +158,21 @@ public class ResponseEntity extends HttpEntity {
return false;
}
ResponseEntity> otherEntity = (ResponseEntity>) other;
- return ObjectUtils.nullSafeEquals(this.statusCode, otherEntity.statusCode);
+ return ObjectUtils.nullSafeEquals(this.status, otherEntity.status);
}
@Override
public int hashCode() {
- return (super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.statusCode));
+ return (super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.status));
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder("<");
- builder.append(this.statusCode.toString());
- if (this.statusCode instanceof HttpStatus) {
+ builder.append(this.status.toString());
+ if (this.status instanceof HttpStatus) {
builder.append(' ');
- builder.append(((HttpStatus) this.statusCode).getReasonPhrase());
+ builder.append(((HttpStatus) this.status).getReasonPhrase());
}
builder.append(',');
T body = getBody();
@@ -328,11 +329,11 @@ public class ResponseEntity extends HttpEntity {
/**
* Set the entity tag of the body, as specified by the {@code ETag} header.
- * @param eTag the new entity tag
+ * @param etag the new entity tag
* @return this builder
* @see HttpHeaders#setETag(String)
*/
- B eTag(String eTag);
+ B eTag(String etag);
/**
* Set the time the resource was last changed, as specified by the
@@ -464,16 +465,16 @@ public class ResponseEntity extends HttpEntity {
}
@Override
- public BodyBuilder eTag(String eTag) {
- if (eTag != null) {
- if (!eTag.startsWith("\"") && !eTag.startsWith("W/\"")) {
- eTag = "\"" + eTag;
+ public BodyBuilder eTag(String etag) {
+ if (etag != null) {
+ if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) {
+ etag = "\"" + etag;
}
- if (!eTag.endsWith("\"")) {
- eTag = eTag + "\"";
+ if (!etag.endsWith("\"")) {
+ etag = etag + "\"";
}
}
- this.headers.setETag(eTag);
+ this.headers.setETag(etag);
return this;
}
diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java
index e27d9f8f0d5..d4ef25cb145 100644
--- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java
+++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsStreamingClientHttpRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -89,9 +89,9 @@ final class HttpComponentsStreamingClientHttpRequest extends AbstractClientHttpR
protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
HttpComponentsClientHttpRequest.addHeaders(this.httpRequest, headers);
- if (this.httpRequest instanceof HttpEntityEnclosingRequest && body != null) {
+ if (this.httpRequest instanceof HttpEntityEnclosingRequest && this.body != null) {
HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest;
- HttpEntity requestEntity = new StreamingHttpEntity(getHeaders(), body);
+ HttpEntity requestEntity = new StreamingHttpEntity(getHeaders(), this.body);
entityEnclosingRequest.setEntity(requestEntity);
}
diff --git a/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java
index 0b13181a295..0815d0ce77a 100644
--- a/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java
+++ b/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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,81 +37,80 @@ import org.springframework.util.concurrent.ListenableFuture;
*/
class InterceptingAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest {
- private AsyncClientHttpRequestFactory requestFactory;
+ private AsyncClientHttpRequestFactory requestFactory;
- private List interceptors;
+ private List interceptors;
- private URI uri;
+ private URI uri;
- private HttpMethod httpMethod;
+ private HttpMethod httpMethod;
- /**
- * Creates new instance of {@link InterceptingAsyncClientHttpRequest}.
- *
- * @param requestFactory the async request factory
- * @param interceptors the list of interceptors
- * @param uri the request URI
- * @param httpMethod the HTTP method
- */
- public InterceptingAsyncClientHttpRequest(AsyncClientHttpRequestFactory requestFactory,
- List interceptors, URI uri, HttpMethod httpMethod) {
+ /**
+ * Create new instance of {@link InterceptingAsyncClientHttpRequest}.
+ * @param requestFactory the async request factory
+ * @param interceptors the list of interceptors
+ * @param uri the request URI
+ * @param httpMethod the HTTP method
+ */
+ public InterceptingAsyncClientHttpRequest(AsyncClientHttpRequestFactory requestFactory,
+ List interceptors, URI uri, HttpMethod httpMethod) {
- this.requestFactory = requestFactory;
- this.interceptors = interceptors;
- this.uri = uri;
- this.httpMethod = httpMethod;
- }
+ this.requestFactory = requestFactory;
+ this.interceptors = interceptors;
+ this.uri = uri;
+ this.httpMethod = httpMethod;
+ }
- @Override
- protected ListenableFuture executeInternal(HttpHeaders headers, byte[] body)
- throws IOException {
+ @Override
+ protected ListenableFuture executeInternal(HttpHeaders headers, byte[] body)
+ throws IOException {
return new AsyncRequestExecution().executeAsync(this, body);
}
- @Override
- public HttpMethod getMethod() {
- return httpMethod;
- }
+ @Override
+ public HttpMethod getMethod() {
+ return this.httpMethod;
+ }
- @Override
- public URI getURI() {
- return uri;
- }
+ @Override
+ public URI getURI() {
+ return uri;
+ }
- private class AsyncRequestExecution implements AsyncClientHttpRequestExecution {
+ private class AsyncRequestExecution implements AsyncClientHttpRequestExecution {
- private Iterator iterator;
+ private Iterator iterator;
- public AsyncRequestExecution() {
- this.iterator = interceptors.iterator();
- }
+ public AsyncRequestExecution() {
+ this.iterator = interceptors.iterator();
+ }
- @Override
- public ListenableFuture executeAsync(HttpRequest request, byte[] body)
- throws IOException {
+ @Override
+ public ListenableFuture executeAsync(HttpRequest request, byte[] body)
+ throws IOException {
- if (this.iterator.hasNext()) {
- AsyncClientHttpRequestInterceptor interceptor = this.iterator.next();
- return interceptor.intercept(request, body, this);
- }
- else {
- URI theUri = request.getURI();
- HttpMethod theMethod = request.getMethod();
- HttpHeaders theHeaders = request.getHeaders();
+ if (this.iterator.hasNext()) {
+ AsyncClientHttpRequestInterceptor interceptor = this.iterator.next();
+ return interceptor.intercept(request, body, this);
+ }
+ else {
+ URI uri = request.getURI();
+ HttpMethod method = request.getMethod();
+ HttpHeaders headers = request.getHeaders();
- AsyncClientHttpRequest delegate = requestFactory.createAsyncRequest(theUri, theMethod);
- delegate.getHeaders().putAll(theHeaders);
- if (body.length > 0) {
- StreamUtils.copy(body, delegate.getBody());
- }
+ AsyncClientHttpRequest delegate = requestFactory.createAsyncRequest(uri, method);
+ delegate.getHeaders().putAll(headers);
+ if (body.length > 0) {
+ StreamUtils.copy(body, delegate.getBody());
+ }
- return delegate.executeAsync();
- }
- }
- }
+ return delegate.executeAsync();
+ }
+ }
+ }
}
diff --git a/spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpResponse.java
index b6a7ed19029..b11256accd5 100644
--- a/spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpResponse.java
+++ b/spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpResponse.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -20,9 +20,11 @@ import java.io.IOException;
import java.io.InputStream;
import okhttp3.Response;
+import okhttp3.ResponseBody;
import org.springframework.http.HttpHeaders;
import org.springframework.util.Assert;
+import org.springframework.util.StreamUtils;
/**
* {@link ClientHttpResponse} implementation based on OkHttp 3.x.
@@ -36,7 +38,7 @@ class OkHttp3ClientHttpResponse extends AbstractClientHttpResponse {
private final Response response;
- private HttpHeaders headers;
+ private volatile HttpHeaders headers;
public OkHttp3ClientHttpResponse(Response response) {
@@ -57,13 +59,15 @@ class OkHttp3ClientHttpResponse extends AbstractClientHttpResponse {
@Override
public InputStream getBody() throws IOException {
- return this.response.body().byteStream();
+ ResponseBody body = this.response.body();
+ return (body != null ? body.byteStream() : StreamUtils.emptyInput());
}
@Override
public HttpHeaders getHeaders() {
- if (this.headers == null) {
- HttpHeaders headers = new HttpHeaders();
+ HttpHeaders headers = this.headers;
+ if (headers == null) {
+ headers = new HttpHeaders();
for (String headerName : this.response.headers().names()) {
for (String headerValue : this.response.headers(headerName)) {
headers.add(headerName, headerValue);
@@ -71,12 +75,15 @@ class OkHttp3ClientHttpResponse extends AbstractClientHttpResponse {
}
this.headers = headers;
}
- return this.headers;
+ return headers;
}
@Override
public void close() {
- this.response.body().close();
+ ResponseBody body = this.response.body();
+ if (body != null) {
+ body.close();
+ }
}
}
diff --git a/spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java
index 9daa030f8b6..a9cc15778da 100644
--- a/spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java
+++ b/spring-web/src/main/java/org/springframework/http/converter/feed/AbstractWireFeedHttpMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -65,8 +65,8 @@ public abstract class AbstractWireFeedHttpMessageConverter e
WireFeedInput feedInput = new WireFeedInput();
MediaType contentType = inputMessage.getHeaders().getContentType();
- Charset charset =
- (contentType != null && contentType.getCharset() != null? contentType.getCharset() : DEFAULT_CHARSET);
+ Charset charset = (contentType != null && contentType.getCharset() != null ?
+ contentType.getCharset() : DEFAULT_CHARSET);
try {
Reader reader = new InputStreamReader(inputMessage.getBody(), charset);
return (T) feedInput.build(reader);
@@ -80,20 +80,17 @@ public abstract class AbstractWireFeedHttpMessageConverter e
protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
- String wireFeedEncoding = wireFeed.getEncoding();
- if (!StringUtils.hasLength(wireFeedEncoding)) {
- wireFeedEncoding = DEFAULT_CHARSET.name();
- }
+ Charset charset = (StringUtils.hasLength(wireFeed.getEncoding()) ?
+ Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET);
MediaType contentType = outputMessage.getHeaders().getContentType();
if (contentType != null) {
- Charset wireFeedCharset = Charset.forName(wireFeedEncoding);
- contentType = new MediaType(contentType.getType(), contentType.getSubtype(), wireFeedCharset);
+ contentType = new MediaType(contentType.getType(), contentType.getSubtype(), charset);
outputMessage.getHeaders().setContentType(contentType);
}
WireFeedOutput feedOutput = new WireFeedOutput();
try {
- Writer writer = new OutputStreamWriter(outputMessage.getBody(), wireFeedEncoding);
+ Writer writer = new OutputStreamWriter(outputMessage.getBody(), charset);
feedOutput.output(wireFeed, writer);
}
catch (FeedException ex) {
diff --git a/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java
index ee83d31f77f..166a6ed550e 100644
--- a/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java
+++ b/spring-web/src/main/java/org/springframework/web/accept/AbstractMappingContentNegotiationStrategy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -87,7 +87,7 @@ public abstract class AbstractMappingContentNegotiationStrategy extends MappingM
/**
* Extract a key from the request to use to look up media types.
- * @return the lookup key or {@code null}.
+ * @return the lookup key, or {@code null} if none
*/
protected abstract String getMediaTypeKey(NativeWebRequest request);
@@ -110,4 +110,4 @@ public abstract class AbstractMappingContentNegotiationStrategy extends MappingM
return null;
}
-}
\ No newline at end of file
+}
diff --git a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java
index 10d80b2bee4..5913da4e7e6 100644
--- a/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java
+++ b/spring-web/src/main/java/org/springframework/web/accept/ServletPathExtensionContentNegotiationStrategy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -38,6 +38,15 @@ public class ServletPathExtensionContentNegotiationStrategy extends PathExtensio
private final ServletContext servletContext;
+ /**
+ * Create an instance without any mappings to start with. Mappings may be
+ * added later when extensions are resolved through
+ * {@link ServletContext#getMimeType(String)} or via JAF.
+ */
+ public ServletPathExtensionContentNegotiationStrategy(ServletContext context) {
+ this(context, null);
+ }
+
/**
* Create an instance with the given extension-to-MediaType lookup.
*/
@@ -49,15 +58,6 @@ public class ServletPathExtensionContentNegotiationStrategy extends PathExtensio
this.servletContext = servletContext;
}
- /**
- * Create an instance without any mappings to start with. Mappings may be
- * added later when extensions are resolved through
- * {@link ServletContext#getMimeType(String)} or via JAF.
- */
- public ServletPathExtensionContentNegotiationStrategy(ServletContext context) {
- this(context, null);
- }
-
/**
* Resolve file extension via {@link ServletContext#getMimeType(String)}
@@ -88,7 +88,7 @@ public class ServletPathExtensionContentNegotiationStrategy extends PathExtensio
* {@link PathExtensionContentNegotiationStrategy#getMediaTypeForResource}
* with the ability to also look up through the ServletContext.
* @param resource the resource to look up
- * @return the MediaType for the extension or {@code null}.
+ * @return the MediaType for the extension, or {@code null} if none found
* @since 4.3
*/
public MediaType getMediaTypeForResource(Resource resource) {
diff --git a/spring-web/src/main/java/org/springframework/web/bind/EscapedErrors.java b/spring-web/src/main/java/org/springframework/web/bind/EscapedErrors.java
index 02885b55ea1..b58d8fddd9a 100644
--- a/spring-web/src/main/java/org/springframework/web/bind/EscapedErrors.java
+++ b/spring-web/src/main/java/org/springframework/web/bind/EscapedErrors.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -19,6 +19,7 @@ package org.springframework.web.bind;
import java.util.ArrayList;
import java.util.List;
+import org.springframework.util.Assert;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
@@ -47,9 +48,7 @@ public class EscapedErrors implements Errors {
* Create a new EscapedErrors instance for the given source instance.
*/
public EscapedErrors(Errors source) {
- if (source == null) {
- throw new IllegalArgumentException("Cannot wrap a null instance");
- }
+ Assert.notNull(source, "Errors source must not be null");
this.source = source;
}
diff --git a/spring-web/src/main/java/org/springframework/web/context/request/NativeWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/NativeWebRequest.java
index 85540990765..906c4f7c57c 100644
--- a/spring-web/src/main/java/org/springframework/web/context/request/NativeWebRequest.java
+++ b/spring-web/src/main/java/org/springframework/web/context/request/NativeWebRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -29,7 +29,7 @@ package org.springframework.web.context.request;
public interface NativeWebRequest extends WebRequest {
/**
- * Return the underlying native request object, if available.
+ * Return the underlying native request object.
* @see javax.servlet.http.HttpServletRequest
* @see javax.portlet.ActionRequest
* @see javax.portlet.RenderRequest
@@ -37,7 +37,7 @@ public interface NativeWebRequest extends WebRequest {
Object getNativeRequest();
/**
- * Return the underlying native response object, if available.
+ * Return the underlying native response object, if any.
* @see javax.servlet.http.HttpServletResponse
* @see javax.portlet.ActionResponse
* @see javax.portlet.RenderResponse
diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java
index ca17e8f1d49..4906310f928 100644
--- a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java
+++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -28,7 +28,6 @@ import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -229,7 +228,6 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
}
boolean validated = validateIfNoneMatch(etag);
-
if (!validated) {
validateIfModifiedSince(lastModifiedTimestamp);
}
@@ -286,6 +284,7 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
if (!StringUtils.hasLength(etag)) {
return false;
}
+
Enumeration ifNoneMatch;
try {
ifNoneMatch = getRequest().getHeaders(IF_NONE_MATCH);
@@ -296,21 +295,22 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
if (!ifNoneMatch.hasMoreElements()) {
return false;
}
+
// We will perform this validation...
etag = padEtagIfNecessary(etag);
while (ifNoneMatch.hasMoreElements()) {
String clientETags = ifNoneMatch.nextElement();
-
- Matcher eTagMatcher = ETAG_HEADER_VALUE_PATTERN.matcher(clientETags);
+ Matcher etagMatcher = ETAG_HEADER_VALUE_PATTERN.matcher(clientETags);
// Compare weak/strong ETags as per https://tools.ietf.org/html/rfc7232#section-2.3
- while (eTagMatcher.find()) {
- if (StringUtils.hasLength(eTagMatcher.group())
- && etag.replaceFirst("^W/", "").equals(eTagMatcher.group(3))) {
+ while (etagMatcher.find()) {
+ if (StringUtils.hasLength(etagMatcher.group()) &&
+ etag.replaceFirst("^W/", "").equals(etagMatcher.group(3))) {
this.notModified = true;
break;
}
}
}
+
return true;
}
diff --git a/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java b/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java
index fc564f3fdb1..abcc2d99d89 100644
--- a/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java
+++ b/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -114,7 +114,7 @@ public class CharacterEncodingFilter extends OncePerRequestFilter {
}
/**
- * Return the configured encoding for requests and/or responses
+ * Return the configured encoding for requests and/or responses.
* @since 4.3
*/
public String getEncoding() {
diff --git a/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java b/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java
index ba5bb5813b4..63c5ee794c9 100644
--- a/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java
+++ b/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -115,7 +115,7 @@ public class DelegatingFilterProxy extends GenericFilterBean {
* @see #setEnvironment(org.springframework.core.env.Environment)
*/
public DelegatingFilterProxy(Filter delegate) {
- Assert.notNull(delegate, "delegate Filter object must not be null");
+ Assert.notNull(delegate, "Delegate Filter must not be null");
this.delegate = delegate;
}
@@ -157,7 +157,7 @@ public class DelegatingFilterProxy extends GenericFilterBean {
* @see #setEnvironment(org.springframework.core.env.Environment)
*/
public DelegatingFilterProxy(String targetBeanName, WebApplicationContext wac) {
- Assert.hasText(targetBeanName, "target Filter bean name must not be null or empty");
+ Assert.hasText(targetBeanName, "Target Filter bean name must not be null or empty");
this.setTargetBeanName(targetBeanName);
this.webApplicationContext = wac;
if (wac != null) {
@@ -246,15 +246,16 @@ public class DelegatingFilterProxy extends GenericFilterBean {
Filter delegateToUse = this.delegate;
if (delegateToUse == null) {
synchronized (this.delegateMonitor) {
- if (this.delegate == null) {
+ delegateToUse = this.delegate;
+ if (delegateToUse == null) {
WebApplicationContext wac = findWebApplicationContext();
if (wac == null) {
throw new IllegalStateException("No WebApplicationContext found: " +
"no ContextLoaderListener or DispatcherServlet registered?");
}
- this.delegate = initDelegate(wac);
+ delegateToUse = initDelegate(wac);
}
- delegateToUse = this.delegate;
+ this.delegate = delegateToUse;
}
}
diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java
index ac2ca82de65..6f0f2f1bd13 100644
--- a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java
+++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java
@@ -27,7 +27,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.springframework.core.ExceptionDepthComparator;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils.MethodFilter;
import org.springframework.web.bind.annotation.ExceptionHandler;
diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java b/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java
index b00f6e46d82..38d6f8829e5 100644
--- a/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java
+++ b/spring-web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -16,9 +16,9 @@
package org.springframework.web.method.annotation;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import org.springframework.web.bind.WebDataBinder;
@@ -39,16 +39,18 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
private final List binderMethods;
+
/**
- * Create a new instance.
- * @param binderMethods {@code @InitBinder} methods, or {@code null}
- * @param initializer for global data binder intialization
+ * Create a new InitBinderDataBinderFactory instance.
+ * @param binderMethods {@code @InitBinder} methods
+ * @param initializer for global data binder initialization
*/
public InitBinderDataBinderFactory(List binderMethods, WebBindingInitializer initializer) {
super(initializer);
- this.binderMethods = (binderMethods != null) ? binderMethods : new ArrayList();
+ this.binderMethods = (binderMethods != null ? binderMethods : Collections.emptyList());
}
+
/**
* Initialize a WebDataBinder with {@code @InitBinder} methods.
* If the {@code @InitBinder} annotation specifies attributes names, it is
@@ -61,22 +63,22 @@ public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
if (isBinderMethodApplicable(binderMethod, binder)) {
Object returnValue = binderMethod.invokeForRequest(request, null, binder);
if (returnValue != null) {
- throw new IllegalStateException("@InitBinder methods should return void: " + binderMethod);
+ throw new IllegalStateException(
+ "@InitBinder methods should return void: " + binderMethod);
}
}
}
}
/**
- * Return {@code true} if the given {@code @InitBinder} method should be
- * invoked to initialize the given WebDataBinder.
- * The default implementation checks if target object name is included
- * in the attribute names specified in the {@code @InitBinder} annotation.
+ * Whether the given {@code @InitBinder} method should be used to initialize
+ * the given WebDataBinder instance. By default we check the attributes
+ * names of the annotation, if present.
*/
protected boolean isBinderMethodApplicable(HandlerMethod initBinderMethod, WebDataBinder binder) {
- InitBinder annot = initBinderMethod.getMethodAnnotation(InitBinder.class);
- Collection names = Arrays.asList(annot.value());
- return (names.size() == 0 || names.contains(binder.getObjectName()));
+ InitBinder ann = initBinderMethod.getMethodAnnotation(InitBinder.class);
+ Collection names = Arrays.asList(ann.value());
+ return (names.isEmpty() || names.contains(binder.getObjectName()));
}
}
diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java
index e0d9e77f8a1..a3c72bcd63b 100644
--- a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java
+++ b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java
@@ -43,6 +43,7 @@ import org.springframework.web.context.request.WebRequest;
* {@link SessionStatus#setComplete()}.
*
* @author Rossen Stoyanchev
+ * @author Juergen Hoeller
* @since 3.1
*/
public class SessionAttributesHandler {
@@ -74,10 +75,7 @@ public class SessionAttributesHandler {
this.attributeNames.addAll(Arrays.asList(annotation.names()));
this.attributeTypes.addAll(Arrays.asList(annotation.types()));
}
-
- for (String attributeName : this.attributeNames) {
- this.knownAttributeNames.add(attributeName);
- }
+ this.knownAttributeNames.addAll(this.attributeNames);
}
/**
@@ -90,7 +88,7 @@ public class SessionAttributesHandler {
/**
* Whether the attribute name or type match the names and types specified
- * via {@code @SessionAttributes} in underlying controller.
+ * via {@code @SessionAttributes} on the underlying controller.
* Attributes successfully resolved through this method are "remembered"
* and subsequently used in {@link #retrieveAttributes(WebRequest)} and
* {@link #cleanupAttributes(WebRequest)}.
@@ -117,7 +115,7 @@ public class SessionAttributesHandler {
public void storeAttributes(WebRequest request, Map attributes) {
for (String name : attributes.keySet()) {
Object value = attributes.get(name);
- Class> attrType = (value != null) ? value.getClass() : null;
+ Class> attrType = (value != null ? value.getClass() : null);
if (isHandlerSessionAttribute(name, attrType)) {
this.sessionAttributeStore.storeAttribute(request, name, value);
}
@@ -158,7 +156,7 @@ public class SessionAttributesHandler {
* A pass-through call to the underlying {@link SessionAttributeStore}.
* @param request the current request
* @param attributeName the name of the attribute of interest
- * @return the attribute value or {@code null}
+ * @return the attribute value, or {@code null} if none
*/
Object retrieveAttribute(WebRequest request, String attributeName) {
return this.sessionAttributeStore.retrieveAttribute(request, attributeName);
diff --git a/spring-web/src/main/java/org/springframework/web/method/support/UriComponentsContributor.java b/spring-web/src/main/java/org/springframework/web/method/support/UriComponentsContributor.java
index 61149b1b014..6cb78ac160e 100644
--- a/spring-web/src/main/java/org/springframework/web/method/support/UriComponentsContributor.java
+++ b/spring-web/src/main/java/org/springframework/web/method/support/UriComponentsContributor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 the original author or authors.
+ * Copyright 2002-2017 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,12 +41,12 @@ public interface UriComponentsContributor {
/**
* Process the given method argument and either update the
- * {@link UriComponentsBuilder} or add to the map with URI variables to use to
- * expand the URI after all arguments are processed.
- * @param parameter the controller method parameter, never {@literal null}.
- * @param value the argument value, possibly {@literal null}.
- * @param builder the builder to update, never {@literal null}.
- * @param uriVariables a map to add URI variables to, never {@literal null}.
+ * {@link UriComponentsBuilder} or add to the map with URI variables
+ * to use to expand the URI after all arguments are processed.
+ * @param parameter the controller method parameter (never {@code null})
+ * @param value the argument value (possibly {@code null})
+ * @param builder the builder to update (never {@code null})
+ * @param uriVariables a map to add URI variables to (never {@code null})
* @param conversionService a ConversionService to format values as Strings
*/
void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder,
diff --git a/spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java b/spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java
index b1dcc25cc88..95c0ab275df 100644
--- a/spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java
+++ b/spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsFileUploadSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -151,6 +151,10 @@ public abstract class CommonsFileUploadSupport {
this.fileUpload.setHeaderEncoding(defaultEncoding);
}
+ /**
+ * Determine the default encoding to use for parsing requests.
+ * @see #setDefaultEncoding
+ */
protected String getDefaultEncoding() {
String encoding = getFileUpload().getHeaderEncoding();
if (encoding == null) {
@@ -172,6 +176,10 @@ public abstract class CommonsFileUploadSupport {
this.uploadTempDirSpecified = true;
}
+ /**
+ * Return the temporary directory where uploaded files get stored.
+ * @see #setUploadTempDir
+ */
protected boolean isUploadTempDirSpecified() {
return this.uploadTempDirSpecified;
}
diff --git a/spring-web/src/main/java/org/springframework/web/util/JavaScriptUtils.java b/spring-web/src/main/java/org/springframework/web/util/JavaScriptUtils.java
index 861b46fe55b..854c5051884 100644
--- a/spring-web/src/main/java/org/springframework/web/util/JavaScriptUtils.java
+++ b/spring-web/src/main/java/org/springframework/web/util/JavaScriptUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -33,7 +33,6 @@ public class JavaScriptUtils {
/**
* Turn JavaScript special characters into escaped characters.
- *
* @param input the input string
* @return the string with escaped characters
*/
diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponents.java b/spring-web/src/main/java/org/springframework/web/util/UriComponents.java
index 739885f954d..c3d165f44ac 100644
--- a/spring-web/src/main/java/org/springframework/web/util/UriComponents.java
+++ b/spring-web/src/main/java/org/springframework/web/util/UriComponents.java
@@ -70,6 +70,13 @@ public abstract class UriComponents implements Serializable {
return this.scheme;
}
+ /**
+ * Return the fragment. Can be {@code null}.
+ */
+ public final String getFragment() {
+ return this.fragment;
+ }
+
/**
* Return the scheme specific part. Can be {@code null}.
*/
@@ -110,13 +117,6 @@ public abstract class UriComponents implements Serializable {
*/
public abstract MultiValueMap getQueryParams();
- /**
- * Return the fragment. Can be {@code null}.
- */
- public final String getFragment() {
- return this.fragment;
- }
-
/**
* Encode all URI components using their specific encoding rules, and returns the
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterChain.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterChain.java
index ac10e6e756d..da4a9093103 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterChain.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterChain.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -33,9 +33,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
- * Mock implementation of the {@link javax.servlet.FilterChain} interface. Used
- * for testing the web framework; also useful for testing custom
- * {@link javax.servlet.Filter} implementations.
+ * Mock implementation of the {@link javax.servlet.FilterChain} interface.
*
*
A {@link MockFilterChain} can be configured with one or more filters and a
* Servlet to invoke. The first time the chain is called, it invokes all filters
@@ -120,10 +118,7 @@ public class MockFilterChain implements FilterChain {
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
Assert.notNull(request, "Request must not be null");
Assert.notNull(response, "Response must not be null");
-
- if (this.request != null) {
- throw new IllegalStateException("This FilterChain has already been called!");
- }
+ Assert.state(this.request == null, "This FilterChain has already been called!");
if (this.iterator == null) {
this.iterator = this.filters.iterator();
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockPageContext.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockPageContext.java
index 76bef2ab2ac..f95752f34dd 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockPageContext.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockPageContext.java
@@ -40,9 +40,7 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.jsp.PageContext} interface.
- *
- *
Used for testing the web framework; only necessary for testing
- * applications when testing custom JSP tags.
+ * Only necessary for testing applications when testing custom JSP tags.
*
*
Note: Expects initialization via the constructor rather than via the
* {@code PageContext.initialize} method. Does not support writing to a
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/MvcNamespaceUtils.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/MvcNamespaceUtils.java
index fb787d1a0a1..72eecdd849f 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/MvcNamespaceUtils.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/MvcNamespaceUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -68,7 +68,9 @@ abstract class MvcNamespaceUtils {
* under that well-known name, unless already registered.
* @return a RuntimeBeanReference to this {@link UrlPathHelper} instance
*/
- public static RuntimeBeanReference registerUrlPathHelper(RuntimeBeanReference urlPathHelperRef, ParserContext parserContext, Object source) {
+ public static RuntimeBeanReference registerUrlPathHelper(
+ RuntimeBeanReference urlPathHelperRef, ParserContext parserContext, Object source) {
+
if (urlPathHelperRef != null) {
if (parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)) {
parserContext.getRegistry().removeAlias(URL_PATH_HELPER_BEAN_NAME);
@@ -91,7 +93,9 @@ abstract class MvcNamespaceUtils {
* under that well-known name, unless already registered.
* @return a RuntimeBeanReference to this {@link PathMatcher} instance
*/
- public static RuntimeBeanReference registerPathMatcher(RuntimeBeanReference pathMatcherRef, ParserContext parserContext, Object source) {
+ public static RuntimeBeanReference registerPathMatcher(
+ RuntimeBeanReference pathMatcherRef, ParserContext parserContext, Object source) {
+
if (pathMatcherRef != null) {
if (parserContext.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME)) {
parserContext.getRegistry().removeAlias(PATH_MATCHER_BEAN_NAME);
@@ -160,7 +164,9 @@ abstract class MvcNamespaceUtils {
* if a non-null CORS configuration is provided.
* @return a RuntimeBeanReference to this {@code Map} instance
*/
- public static RuntimeBeanReference registerCorsConfigurations(Map corsConfigurations, ParserContext parserContext, Object source) {
+ public static RuntimeBeanReference registerCorsConfigurations(
+ Map corsConfigurations, ParserContext parserContext, Object source) {
+
if (!parserContext.getRegistry().containsBeanDefinition(CORS_CONFIGURATION_BEAN_NAME)) {
RootBeanDefinition corsConfigurationsDef = new RootBeanDefinition(LinkedHashMap.class);
corsConfigurationsDef.setSource(source);
@@ -181,7 +187,7 @@ abstract class MvcNamespaceUtils {
/**
* Find the {@code ContentNegotiationManager} bean created by or registered
* with the {@code annotation-driven} element.
- * @return a bean definition, bean reference, or null.
+ * @return a bean definition, bean reference, or {@code null}
*/
public static Object getContentNegotiationManager(ParserContext context) {
String name = AnnotationDrivenBeanDefinitionParser.HANDLER_MAPPING_BEAN_NAME;
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java
index 06d61dc1c04..e514caf7351 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -36,9 +36,9 @@ import org.springframework.web.servlet.view.RedirectView;
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that
* parses the following MVC namespace elements:
*
- * {@code }
- * {@code }
- * {@code }
+ * {@code }
+ * {@code }
+ * {@code }
*
*
* All elements result in the registration of a
@@ -55,7 +55,7 @@ import org.springframework.web.servlet.view.RedirectView;
class ViewControllerBeanDefinitionParser implements BeanDefinitionParser {
private static final String HANDLER_MAPPING_BEAN_NAME =
- "org.springframework.web.servlet.config.viewControllerHandlerMapping";
+ "org.springframework.web.servlet.config.viewControllerHandlerMapping";
@Override
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java
index a91c937dfd6..a8c8c53dc58 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -130,19 +130,19 @@ public class ViewResolversBeanDefinitionParser implements BeanDefinitionParser {
compositeResolverBeanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
names = new String[] {"content-negotiation"};
- List contentnNegotiationElements = DomUtils.getChildElementsByTagName(element, names);
- if (contentnNegotiationElements.isEmpty()) {
+ List contentNegotiationElements = DomUtils.getChildElementsByTagName(element, names);
+ if (contentNegotiationElements.isEmpty()) {
compositeResolverBeanDef.getPropertyValues().add("viewResolvers", resolvers);
}
- else if (contentnNegotiationElements.size() == 1) {
- BeanDefinition beanDef = createContentNegotiatingViewResolver(contentnNegotiationElements.get(0), context);
+ else if (contentNegotiationElements.size() == 1) {
+ BeanDefinition beanDef = createContentNegotiatingViewResolver(contentNegotiationElements.get(0), context);
beanDef.getPropertyValues().add("viewResolvers", resolvers);
ManagedList list = new ManagedList(1);
list.add(beanDef);
compositeResolverBeanDef.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
compositeResolverBeanDef.getPropertyValues().add("viewResolvers", list);
}
- else if (contentnNegotiationElements.size() > 1) {
+ else {
throw new IllegalArgumentException("Only one element is allowed.");
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java
index 8a164b574c4..a1dc62a8d46 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -51,11 +51,9 @@ public class AsyncSupportConfigurer {
* Set the default {@link AsyncTaskExecutor} to use when a controller method
* returns a {@link Callable}. Controller methods can override this default on
* a per-request basis by returning a {@link WebAsyncTask}.
- *
* By default a {@link SimpleAsyncTaskExecutor} instance is used, and it's
* highly recommended to change that default in production since the simple
* executor does not re-use threads.
- *
* @param taskExecutor the task executor instance to use by default
*/
public AsyncSupportConfigurer setTaskExecutor(AsyncTaskExecutor taskExecutor) {
@@ -70,7 +68,6 @@ public class AsyncSupportConfigurer {
* for further processing of the concurrently produced result.
*
If this value is not set, the default timeout of the underlying
* implementation is used, e.g. 10 seconds on Tomcat with Servlet 3.
- *
* @param timeout the timeout value in milliseconds
*/
public AsyncSupportConfigurer setDefaultTimeout(long timeout) {
@@ -82,7 +79,6 @@ public class AsyncSupportConfigurer {
* Configure lifecycle interceptors with callbacks around concurrent request
* execution that starts when a controller returns a
* {@link java.util.concurrent.Callable}.
- *
* @param interceptors the interceptors to register
*/
public AsyncSupportConfigurer registerCallableInterceptors(CallableProcessingInterceptor... interceptors) {
@@ -94,7 +90,6 @@ public class AsyncSupportConfigurer {
/**
* Configure lifecycle interceptors with callbacks around concurrent request
* execution that starts when a controller returns a {@link DeferredResult}.
- *
* @param interceptors the interceptors to register
*/
public AsyncSupportConfigurer registerDeferredResultInterceptors(DeferredResultProcessingInterceptor... interceptors) {
@@ -103,6 +98,7 @@ public class AsyncSupportConfigurer {
return this;
}
+
protected AsyncTaskExecutor getTaskExecutor() {
return this.taskExecutor;
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java
index c22dda7312d..15227575e80 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -30,40 +30,45 @@ import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;
/**
* Creates a {@code ContentNegotiationManager} and configures it with
- * one or more {@link ContentNegotiationStrategy} instances. The following shows
- * the resulting strategy instances, the methods used to configured them, and
- * whether enabled by default:
+ * one or more {@link ContentNegotiationStrategy} instances.
+ *
+ *
As of 5.0 you can set the exact strategies to use via
+ * {@link #strategies(List)}.
+ *
+ *
As an alternative you can also rely on the set of defaults described below
+ * which can be turned on or off or customized through the methods of this
+ * builder:
*
*
*
- * Configurer Property
- * Underlying Strategy
- * Default Setting
+ * Configurer Property
+ * Underlying Strategy
+ * Default Setting
*
*
- * {@link #favorPathExtension}
- * {@link PathExtensionContentNegotiationStrategy Path Extension strategy}
- * On
+ * {@link #favorPathExtension}
+ * {@link PathExtensionContentNegotiationStrategy Path Extension strategy}
+ * On
*
*
- * {@link #favorParameter}
- * {@link ParameterContentNegotiationStrategy Parameter strategy}
- * Off
+ * {@link #favorParameter}
+ * {@link ParameterContentNegotiationStrategy Parameter strategy}
+ * Off
*
*
- * {@link #ignoreAcceptHeader}
- * {@link HeaderContentNegotiationStrategy Header strategy}
- * On
+ * {@link #ignoreAcceptHeader}
+ * {@link HeaderContentNegotiationStrategy Header strategy}
+ * On
*
*
- * {@link #defaultContentType}
- * {@link FixedContentNegotiationStrategy Fixed content strategy}
- * Not set
+ * {@link #defaultContentType}
+ * {@link FixedContentNegotiationStrategy Fixed content strategy}
+ * Not set
*
*
- * {@link #defaultContentTypeStrategy}
- * {@link ContentNegotiationStrategy}
- * Not set
+ * {@link #defaultContentTypeStrategy}
+ * {@link ContentNegotiationStrategy}
+ * Not set
*
*
*
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java
index 76db94f9700..bfc70a2aab0 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DefaultServletHandlerConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -28,15 +28,18 @@ import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler;
/**
- * Configures a request handler for serving static resources by forwarding the request to the Servlet container's
- * "default" Servlet. This is intended to be used when the Spring MVC {@link DispatcherServlet} is mapped to "/"
- * thus overriding the Servlet container's default handling of static resources. Since this handler is configured
- * at the lowest precedence, effectively it allows all other handler mappings to handle the request, and if none
+ * Configures a request handler for serving static resources by forwarding
+ * the request to the Servlet container's "default" Servlet. This is intended
+ * to be used when the Spring MVC {@link DispatcherServlet} is mapped to "/"
+ * thus overriding the Servlet container's default handling of static resources.
+ *
+ * Since this handler is configured at the lowest precedence, effectively
+ * it allows all other handler mappings to handle the request, and if none
* of them do, this handler can forward it to the "default" Servlet.
*
* @author Rossen Stoyanchev
+ * @author Juergen Hoeller
* @since 3.1
- *
* @see DefaultServletHttpRequestHandler
*/
public class DefaultServletHandlerConfigurer {
@@ -45,19 +48,22 @@ public class DefaultServletHandlerConfigurer {
private DefaultServletHttpRequestHandler handler;
+
/**
* Create a {@link DefaultServletHandlerConfigurer} instance.
- * @param servletContext the ServletContext to use to configure the underlying DefaultServletHttpRequestHandler.
+ * @param servletContext the ServletContext to use.
*/
public DefaultServletHandlerConfigurer(ServletContext servletContext) {
- Assert.notNull(servletContext, "A ServletContext is required to configure default servlet handling");
+ Assert.notNull(servletContext, "ServletContext is required");
this.servletContext = servletContext;
}
+
/**
- * Enable forwarding to the "default" Servlet. When this method is used the {@link DefaultServletHttpRequestHandler}
- * will try to auto-detect the "default" Servlet name. Alternatively, you can specify the name of the default
- * Servlet via {@link #enable(String)}.
+ * Enable forwarding to the "default" Servlet.
+ *
When this method is used the {@link DefaultServletHttpRequestHandler}
+ * will try to autodetect the "default" Servlet name. Alternatively, you can
+ * specify the name of the default Servlet via {@link #enable(String)}.
* @see DefaultServletHttpRequestHandler
*/
public void enable() {
@@ -66,27 +72,28 @@ public class DefaultServletHandlerConfigurer {
/**
* Enable forwarding to the "default" Servlet identified by the given name.
- * This is useful when the default Servlet cannot be auto-detected, for example when it has been manually configured.
+ *
This is useful when the default Servlet cannot be autodetected,
+ * for example when it has been manually configured.
* @see DefaultServletHttpRequestHandler
*/
public void enable(String defaultServletName) {
- handler = new DefaultServletHttpRequestHandler();
- handler.setDefaultServletName(defaultServletName);
- handler.setServletContext(servletContext);
+ this.handler = new DefaultServletHttpRequestHandler();
+ this.handler.setDefaultServletName(defaultServletName);
+ this.handler.setServletContext(this.servletContext);
}
/**
* Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the
- * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"}; or {@code null} if
- * default servlet handling was not been enabled.
+ * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"};
+ * or {@code null} if default servlet handling was not been enabled.
*/
protected AbstractHandlerMapping getHandlerMapping() {
- if (handler == null) {
+ if (this.handler == null) {
return null;
}
Map urlMap = new HashMap();
- urlMap.put("/**", handler);
+ urlMap.put("/**", this.handler);
SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
handlerMapping.setOrder(Integer.MAX_VALUE);
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java
index 025eef884d3..07ec3c6a485 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistry.java
index 5e2f45eecf6..54aea4a4a4e 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistry.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistry.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -28,13 +28,13 @@ import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapt
*
* @author Rossen Stoyanchev
* @author Keith Donald
- *
* @since 3.1
*/
public class InterceptorRegistry {
private final List registrations = new ArrayList();
+
/**
* Adds the provided {@link HandlerInterceptor}.
* @param interceptor the interceptor to add
@@ -43,7 +43,7 @@ public class InterceptorRegistry {
*/
public InterceptorRegistration addInterceptor(HandlerInterceptor interceptor) {
InterceptorRegistration registration = new InterceptorRegistration(interceptor);
- registrations.add(registration);
+ this.registrations.add(registration);
return registration;
}
@@ -56,16 +56,16 @@ public class InterceptorRegistry {
public InterceptorRegistration addWebRequestInterceptor(WebRequestInterceptor interceptor) {
WebRequestHandlerInterceptorAdapter adapted = new WebRequestHandlerInterceptorAdapter(interceptor);
InterceptorRegistration registration = new InterceptorRegistration(adapted);
- registrations.add(registration);
+ this.registrations.add(registration);
return registration;
}
/**
- * Returns all registered interceptors.
+ * Return all registered interceptors.
*/
protected List getInterceptors() {
- List interceptors = new ArrayList();
- for (InterceptorRegistration registration : registrations) {
+ List interceptors = new ArrayList(this.registrations.size());
+ for (InterceptorRegistration registration : this.registrations) {
interceptors.add(registration.getInterceptor());
}
return interceptors ;
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java
index bc21e6e0b55..79a70333055 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -98,7 +98,6 @@ public class ViewResolverRegistry {
* media types requested by the client (e.g. in the Accept header).
* If invoked multiple times the provided default views will be added to
* any other default views that may have been configured already.
- *
* @see ContentNegotiatingViewResolver#setDefaultViews
*/
public void enableContentNegotiation(boolean useNotAcceptableStatus, View... defaultViews) {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
index c60b6a80b7e..6d4ef78474e 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
@@ -26,8 +26,6 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.xml.transform.Source;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.BeanInitializationException;
@@ -369,7 +367,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
try {
this.contentNegotiationManager = configurer.getContentNegotiationManager();
}
- catch (Exception ex) {
+ catch (Throwable ex) {
throw new BeanInitializationException("Could not create ContentNegotiationManager", ex);
}
}
@@ -765,16 +763,16 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
}
if (jackson2XmlPresent) {
- ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build();
- messageConverters.add(new MappingJackson2XmlHttpMessageConverter(objectMapper));
+ messageConverters.add(new MappingJackson2XmlHttpMessageConverter(
+ Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build()));
}
else if (jaxb2Present) {
messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
}
if (jackson2Present) {
- ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build();
- messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper));
+ messageConverters.add(new MappingJackson2HttpMessageConverter(
+ Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build()));
}
else if (gsonPresent) {
messageConverters.add(new GsonHttpMessageConverter());
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
index 1117cb6bcf6..474d16baffa 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -78,9 +78,9 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
private final List adaptedInterceptors = new ArrayList();
- private CorsProcessor corsProcessor = new DefaultCorsProcessor();
+ private final UrlBasedCorsConfigurationSource globalCorsConfigSource = new UrlBasedCorsConfigurationSource();
- private final UrlBasedCorsConfigurationSource corsConfigSource = new UrlBasedCorsConfigurationSource();
+ private CorsProcessor corsProcessor = new DefaultCorsProcessor();
/**
@@ -123,7 +123,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
*/
public void setAlwaysUseFullPath(boolean alwaysUseFullPath) {
this.urlPathHelper.setAlwaysUseFullPath(alwaysUseFullPath);
- this.corsConfigSource.setAlwaysUseFullPath(alwaysUseFullPath);
+ this.globalCorsConfigSource.setAlwaysUseFullPath(alwaysUseFullPath);
}
/**
@@ -135,7 +135,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
*/
public void setUrlDecode(boolean urlDecode) {
this.urlPathHelper.setUrlDecode(urlDecode);
- this.corsConfigSource.setUrlDecode(urlDecode);
+ this.globalCorsConfigSource.setUrlDecode(urlDecode);
}
/**
@@ -145,7 +145,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
*/
public void setRemoveSemicolonContent(boolean removeSemicolonContent) {
this.urlPathHelper.setRemoveSemicolonContent(removeSemicolonContent);
- this.corsConfigSource.setRemoveSemicolonContent(removeSemicolonContent);
+ this.globalCorsConfigSource.setRemoveSemicolonContent(removeSemicolonContent);
}
/**
@@ -157,7 +157,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
Assert.notNull(urlPathHelper, "UrlPathHelper must not be null");
this.urlPathHelper = urlPathHelper;
- this.corsConfigSource.setUrlPathHelper(urlPathHelper);
+ this.globalCorsConfigSource.setUrlPathHelper(urlPathHelper);
}
/**
@@ -175,7 +175,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
public void setPathMatcher(PathMatcher pathMatcher) {
Assert.notNull(pathMatcher, "PathMatcher must not be null");
this.pathMatcher = pathMatcher;
- this.corsConfigSource.setPathMatcher(pathMatcher);
+ this.globalCorsConfigSource.setPathMatcher(pathMatcher);
}
/**
@@ -191,7 +191,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
* Supported interceptor types are HandlerInterceptor, WebRequestInterceptor, and MappedInterceptor.
* Mapped interceptors apply only to request URLs that match its path patterns.
* Mapped interceptor beans are also detected by type during initialization.
- * @param interceptors array of handler interceptors, or {@code null} if none
+ * @param interceptors array of handler interceptors
* @see #adaptInterceptor
* @see org.springframework.web.servlet.HandlerInterceptor
* @see org.springframework.web.context.request.WebRequestInterceptor
@@ -200,6 +200,23 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
this.interceptors.addAll(Arrays.asList(interceptors));
}
+ /**
+ * Set "global" CORS configuration based on URL patterns. By default the first
+ * matching URL pattern is combined with the CORS configuration for the
+ * handler, if any.
+ * @since 4.2
+ */
+ public void setCorsConfigurations(Map corsConfigurations) {
+ this.globalCorsConfigSource.setCorsConfigurations(corsConfigurations);
+ }
+
+ /**
+ * Get the "global" CORS configuration.
+ */
+ public Map getCorsConfigurations() {
+ return this.globalCorsConfigSource.getCorsConfigurations();
+ }
+
/**
* Configure a custom {@link CorsProcessor} to use to apply the matched
* {@link CorsConfiguration} for a request.
@@ -218,23 +235,6 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
return this.corsProcessor;
}
- /**
- * Set "global" CORS configuration based on URL patterns. By default the first
- * matching URL pattern is combined with the CORS configuration for the
- * handler, if any.
- * @since 4.2
- */
- public void setCorsConfigurations(Map corsConfigurations) {
- this.corsConfigSource.setCorsConfigurations(corsConfigurations);
- }
-
- /**
- * Get the CORS configuration.
- */
- public Map getCorsConfigurations() {
- return this.corsConfigSource.getCorsConfigurations();
- }
-
/**
* Initializes the interceptors.
@@ -364,7 +364,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
HandlerExecutionChain executionChain = getHandlerExecutionChain(handler, request);
if (CorsUtils.isCorsRequest(request)) {
- CorsConfiguration globalConfig = this.corsConfigSource.getCorsConfiguration(request);
+ CorsConfiguration globalConfig = this.globalCorsConfigSource.getCorsConfiguration(request);
CorsConfiguration handlerConfig = getCorsConfiguration(handler, request);
CorsConfiguration config = (globalConfig != null ? globalConfig.combine(handlerConfig) : handlerConfig);
executionChain = getCorsHandlerExecutionChain(request, executionChain, config);
@@ -433,15 +433,16 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
* Retrieve the CORS configuration for the given handler.
* @param handler the handler to check (never {@code null}).
* @param request the current request.
- * @return the CORS configuration for the handler or {@code null}.
+ * @return the CORS configuration for the handler, or {@code null} if none
* @since 4.2
*/
protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) {
+ Object resolvedHandler = handler;
if (handler instanceof HandlerExecutionChain) {
- handler = ((HandlerExecutionChain) handler).getHandler();
+ resolvedHandler = ((HandlerExecutionChain) handler).getHandler();
}
- if (handler instanceof CorsConfigurationSource) {
- return ((CorsConfigurationSource) handler).getCorsConfiguration(request);
+ if (resolvedHandler instanceof CorsConfigurationSource) {
+ return ((CorsConfigurationSource) resolvedHandler).getCorsConfiguration(request);
}
return null;
}
@@ -455,7 +456,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport
* HandlerInterceptor that makes CORS-related checks and adds CORS headers.
* @param request the current request
* @param chain the handler chain
- * @param config the applicable CORS configuration, possibly {@code null}
+ * @param config the applicable CORS configuration (possibly {@code null})
* @since 4.2
*/
protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest request,
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerExceptionResolverComposite.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerExceptionResolverComposite.java
index 09e6a513f67..238ad765273 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerExceptionResolverComposite.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerExceptionResolverComposite.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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,14 +37,6 @@ public class HandlerExceptionResolverComposite implements HandlerExceptionResolv
private int order = Ordered.LOWEST_PRECEDENCE;
- public void setOrder(int order) {
- this.order = order;
- }
-
- @Override
- public int getOrder() {
- return this.order;
- }
/**
* Set the list of exception resolvers to delegate to.
@@ -57,20 +49,30 @@ public class HandlerExceptionResolverComposite implements HandlerExceptionResolv
* Return the list of exception resolvers to delegate to.
*/
public List getExceptionResolvers() {
- return Collections.unmodifiableList(resolvers);
+ return (this.resolvers != null ? Collections.unmodifiableList(this.resolvers) :
+ Collections.emptyList());
}
+ public void setOrder(int order) {
+ this.order = order;
+ }
+
+ @Override
+ public int getOrder() {
+ return this.order;
+ }
+
+
/**
* Resolve the exception by iterating over the list of configured exception resolvers.
* The first one to return a ModelAndView instance wins. Otherwise {@code null} is returned.
*/
@Override
- public ModelAndView resolveException(HttpServletRequest request,
- HttpServletResponse response,
- Object handler,
- Exception ex) {
- if (resolvers != null) {
- for (HandlerExceptionResolver handlerExceptionResolver : resolvers) {
+ public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
+ Object handler,Exception ex) {
+
+ if (this.resolvers != null) {
+ for (HandlerExceptionResolver handlerExceptionResolver : this.resolvers) {
ModelAndView mav = handlerExceptionResolver.resolveException(request, response, handler, ex);
if (mav != null) {
return mav;
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java
index 3d84a0ed337..686edc44ae8 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -35,20 +35,22 @@ abstract class AbstractNameValueExpression implements NameValueExpression
protected final boolean isNegated;
+
AbstractNameValueExpression(String expression) {
int separator = expression.indexOf('=');
if (separator == -1) {
this.isNegated = expression.startsWith("!");
- this.name = isNegated ? expression.substring(1) : expression;
+ this.name = (this.isNegated ? expression.substring(1) : expression);
this.value = null;
}
else {
this.isNegated = (separator > 0) && (expression.charAt(separator - 1) == '!');
- this.name = isNegated ? expression.substring(0, separator - 1) : expression.substring(0, separator);
+ this.name = (this.isNegated ? expression.substring(0, separator - 1) : expression.substring(0, separator));
this.value = parseValue(expression.substring(separator + 1));
}
}
+
@Override
public String getName() {
return this.name;
@@ -64,10 +66,6 @@ abstract class AbstractNameValueExpression implements NameValueExpression
return this.isNegated;
}
- protected abstract boolean isCaseSensitiveName();
-
- protected abstract T parseValue(String valueExpression);
-
public final boolean match(HttpServletRequest request) {
boolean isMatch;
if (this.value != null) {
@@ -76,23 +74,29 @@ abstract class AbstractNameValueExpression implements NameValueExpression
else {
isMatch = matchName(request);
}
- return isNegated ? !isMatch : isMatch;
+ return (this.isNegated ? !isMatch : isMatch);
}
+
+ protected abstract boolean isCaseSensitiveName();
+
+ protected abstract T parseValue(String valueExpression);
+
protected abstract boolean matchName(HttpServletRequest request);
protected abstract boolean matchValue(HttpServletRequest request);
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- if (obj != null && obj instanceof AbstractNameValueExpression) {
+ if (obj instanceof AbstractNameValueExpression) {
AbstractNameValueExpression> other = (AbstractNameValueExpression>) obj;
- String thisName = isCaseSensitiveName() ? this.name : this.name.toLowerCase();
- String otherName = isCaseSensitiveName() ? other.name : other.name.toLowerCase();
- return ((thisName.equalsIgnoreCase(otherName)) &&
+ String thisName = (isCaseSensitiveName() ? this.name : this.name.toLowerCase());
+ String otherName = (isCaseSensitiveName() ? other.name : other.name.toLowerCase());
+ return (thisName.equalsIgnoreCase(otherName) &&
(this.value != null ? this.value.equals(other.value) : other.value == null) &&
this.isNegated == other.isNegated);
}
@@ -101,29 +105,30 @@ abstract class AbstractNameValueExpression implements NameValueExpression
@Override
public int hashCode() {
- int result = isCaseSensitiveName() ? name.hashCode() : name.toLowerCase().hashCode();
- result = 31 * result + (value != null ? value.hashCode() : 0);
- result = 31 * result + (isNegated ? 1 : 0);
+ int result = (isCaseSensitiveName() ? this.name.hashCode() : this.name.toLowerCase().hashCode());
+ result = 31 * result + (this.value != null ? this.value.hashCode() : 0);
+ result = 31 * result + (this.isNegated ? 1 : 0);
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
- if (value != null) {
- builder.append(name);
- if (isNegated) {
+ if (this.value != null) {
+ builder.append(this.name);
+ if (this.isNegated) {
builder.append('!');
}
builder.append('=');
- builder.append(value);
+ builder.append(this.value);
}
else {
- if (isNegated) {
+ if (this.isNegated) {
builder.append('!');
}
- builder.append(name);
+ builder.append(this.name);
}
return builder.toString();
}
+
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java
index aaa0847c7a0..1eecb207355 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -22,6 +22,7 @@ import java.util.LinkedHashSet;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
+import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.cors.CorsUtils;
@@ -158,12 +159,12 @@ public final class HeadersRequestCondition extends AbstractRequestCondition getFileExtensions() {
- if (useRegisteredSuffixPatternMatch() && getContentNegotiationManager() != null) {
+ if (useRegisteredSuffixPatternMatch() && this.contentNegotiationManager != null) {
return this.contentNegotiationManager.getAllFileExtensions();
}
return null;
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java
index b195f353a8a..7011eaef5b1 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java
@@ -46,14 +46,14 @@ public class HttpHeadersReturnValueHandler implements HandlerMethodReturnValueHa
mavContainer.setRequestHandled(true);
- Assert.isInstanceOf(HttpHeaders.class, returnValue, "HttpHeaders expected");
+ Assert.state(returnValue instanceof HttpHeaders, "HttpHeaders expected");
HttpHeaders headers = (HttpHeaders) returnValue;
if (!headers.isEmpty()) {
HttpServletResponse servletResponse = webRequest.getNativeResponse(HttpServletResponse.class);
ServletServerHttpResponse outputMessage = new ServletServerHttpResponse(servletResponse);
outputMessage.getHeaders().putAll(headers);
- outputMessage.getBody(); // flush headers
+ outputMessage.getBody(); // flush headers
}
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
index 0cc38d36136..ac2fbf714b4 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java
@@ -218,7 +218,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* not initialized yet via {@link #afterPropertiesSet()}.
*/
public List getArgumentResolvers() {
- return (this.argumentResolvers != null) ? this.argumentResolvers.getResolvers() : null;
+ return (this.argumentResolvers != null ? this.argumentResolvers.getResolvers() : null);
}
/**
@@ -239,7 +239,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* {@code null} if not initialized yet via {@link #afterPropertiesSet()}.
*/
public List getInitBinderArgumentResolvers() {
- return (this.initBinderArgumentResolvers != null) ? this.initBinderArgumentResolvers.getResolvers() : null;
+ return (this.initBinderArgumentResolvers != null ? this.initBinderArgumentResolvers.getResolvers() : null);
}
/**
@@ -277,7 +277,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* initialized yet via {@link #afterPropertiesSet()}.
*/
public List getReturnValueHandlers() {
- return this.returnValueHandlers.getHandlers();
+ return (this.returnValueHandlers != null ? this.returnValueHandlers.getHandlers() : null);
}
/**
@@ -302,7 +302,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
* Return the configured {@link ModelAndViewResolver}s, or {@code null}.
*/
public List getModelAndViewResolvers() {
- return modelAndViewResolvers;
+ return this.modelAndViewResolvers;
}
/**
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java
index d41295cfa11..284eecfa50c 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -31,7 +31,6 @@ import org.springframework.http.server.ServerHttpResponse;
import org.springframework.util.CollectionUtils;
import org.springframework.web.method.ControllerAdviceBean;
-
/**
* Invokes {@link RequestBodyAdvice} and {@link ResponseBodyAdvice} where each
* instance may be (and is most likely) wrapped with
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java
index d8d3208437d..9fc46f2316d 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -38,7 +38,6 @@ import org.springframework.web.util.UriComponentsBuilder;
*/
public class UriComponentsBuilderMethodArgumentResolver implements HandlerMethodArgumentResolver {
-
@Override
public boolean supportsParameter(MethodParameter parameter) {
Class> type = parameter.getParameterType();
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMap.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMap.java
index 66c811837bc..18c542681b1 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMap.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMap.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -38,13 +38,6 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
private final ModelMap flashAttributes = new ModelMap();
- /**
- * Class constructor.
- * @param dataBinder used to format attribute values as Strings.
- */
- public RedirectAttributesModelMap(DataBinder dataBinder) {
- this.dataBinder = dataBinder;
- }
/**
* Default constructor without a DataBinder.
@@ -54,6 +47,15 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
this(null);
}
+ /**
+ * Constructor with a DataBinder.
+ * @param dataBinder used to format attribute values as Strings
+ */
+ public RedirectAttributesModelMap(DataBinder dataBinder) {
+ this.dataBinder = dataBinder;
+ }
+
+
/**
* Return the attributes candidate for flash storage or an empty Map.
*/
@@ -76,7 +78,7 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr
if (value == null) {
return null;
}
- return (dataBinder != null) ? dataBinder.convertIfNecessary(value, String.class) : value.toString();
+ return (this.dataBinder != null ? this.dataBinder.convertIfNecessary(value, String.class) : value.toString());
}
/**
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java
index 4c457db2a89..b37838a8c6f 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/GzipResourceResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -46,7 +46,7 @@ public class GzipResourceResolver extends AbstractResourceResolver {
List extends Resource> locations, ResourceResolverChain chain) {
Resource resource = chain.resolveResource(request, requestPath, locations);
- if ((resource == null) || (request != null && !isGzipAccepted(request))) {
+ if (resource == null || (request != null && !isGzipAccepted(request))) {
return resource;
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java
index c3f0b5e2d6f..2906e5663cd 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -53,7 +53,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
}
/**
- * @return the configured {@code ResourceUrlProvider}.
+ * Return the configured {@code ResourceUrlProvider}.
*/
public ResourceUrlProvider getResourceUrlProvider() {
return this.resourceUrlProvider;
@@ -69,7 +69,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer
* @param request the current request
* @param resource the resource being transformed
* @param transformerChain the transformer chain
- * @return the resolved URL or null
+ * @return the resolved URL, or {@code} if not resolvable
*/
protected String resolveUrlPath(String resourcePath, HttpServletRequest request,
Resource resource, ResourceTransformerChain transformerChain) {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java
index f32e73806ba..c4f338b0865 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -20,7 +20,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -35,7 +34,6 @@ import org.springframework.web.servlet.FlashMap;
import org.springframework.web.servlet.FlashMapManager;
import org.springframework.web.util.UrlPathHelper;
-
/**
* A base class for {@link FlashMapManager} implementations.
*
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java
index afe4de6c9a0..73ea712d065 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -79,7 +79,7 @@ public class EscapeBodyTag extends HtmlEscapingAwareTag implements BodyTag {
String content = readBodyContent();
// HTML and/or JavaScript escape, if demanded
content = htmlEscape(content);
- content = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content;
+ content = (this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(content) : content);
writeBodyContent(content);
}
catch (IOException ex) {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java
index 16dc88c8386..e2106289398 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -227,8 +227,7 @@ public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware {
// We have a code or default text that we need to resolve.
Object[] argumentsArray = resolveArguments(this.arguments);
if (!this.nestedArguments.isEmpty()) {
- argumentsArray = appendArguments(argumentsArray,
- this.nestedArguments.toArray());
+ argumentsArray = appendArguments(argumentsArray, this.nestedArguments.toArray());
}
if (this.text != null) {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/Param.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/Param.java
index 8909c3598dd..ce3fc8d7a49 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/Param.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/Param.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -33,37 +33,39 @@ public class Param {
private String value;
- /**
- * @return the raw parameter name
- */
- public String getName() {
- return name;
- }
/**
- * Set the raw name of the parameter
+ * Set the raw name of the parameter.
*/
public void setName(String name) {
this.name = name;
}
/**
- * @return the raw parameter value
+ * Return the raw parameter name.
*/
- public String getValue() {
- return value;
+ public String getName() {
+ return this.name;
}
/**
- * Set the raw value of the parameter
+ * Set the raw value of the parameter.
*/
public void setValue(String value) {
this.value = value;
}
+ /**
+ * Return the raw parameter value
+ */
+ public String getValue() {
+ return this.value;
+ }
+
+
@Override
public String toString() {
- return "JSP Tag Param: name '" + name + "', value '" + value + "'";
+ return "JSP Tag Param: name '" + this.name + "', value '" + this.value + "'";
}
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java
index 6dc0925e099..fd60e9dece1 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -196,11 +196,11 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
/**
* Build the URL for the tag from the tag attributes and parameters.
* @return the URL value as a String
- * @throws JspException
*/
private String createUrl() throws JspException {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
+
StringBuilder url = new StringBuilder();
if (this.type == UrlType.CONTEXT_RELATIVE) {
// add application context to url
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java
index 3ccd819b5b1..dd49bfc78d4 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -57,7 +57,7 @@ public class ButtonTag extends AbstractHtmlElementTag {
*/
@Override
public String getName() {
- return name;
+ return this.name;
}
/**
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractUrlBasedView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractUrlBasedView.java
index 39f2c3b0952..50a7f13c27c 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractUrlBasedView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractUrlBasedView.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -92,9 +92,7 @@ public abstract class AbstractUrlBasedView extends AbstractView implements Initi
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(super.toString());
- sb.append("; URL [").append(getUrl()).append("]");
- return sb.toString();
+ return super.toString() + "; URL [" + getUrl() + "]";
}
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java
index 83eb9241237..b5d5d41c1ff 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -66,8 +66,6 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
private static final int OUTPUT_BYTE_ARRAY_INITIAL_SIZE = 4096;
- private String beanName;
-
private String contentType = DEFAULT_CONTENT_TYPE;
private String requestContextAttribute;
@@ -80,23 +78,8 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
private Set exposedContextBeanNames;
+ private String beanName;
- /**
- * Set the view's name. Helpful for traceability.
- * Framework code must call this when constructing views.
- */
- @Override
- public void setBeanName(String beanName) {
- this.beanName = beanName;
- }
-
- /**
- * Return the view's name. Should never be {@code null},
- * if the view was correctly configured.
- */
- public String getBeanName() {
- return this.beanName;
- }
/**
* Set the content type for this view.
@@ -284,6 +267,23 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
this.exposedContextBeanNames = new HashSet(Arrays.asList(exposedContextBeanNames));
}
+ /**
+ * Set the view's name. Helpful for traceability.
+ * Framework code must call this when constructing views.
+ */
+ @Override
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ /**
+ * Return the view's name. Should never be {@code null},
+ * if the view was correctly configured.
+ */
+ public String getBeanName() {
+ return this.beanName;
+ }
+
/**
* Prepares the view given the specified model, merging it with static
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java
index 7b7067506f0..f1a46b2db1e 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java
@@ -87,8 +87,6 @@ import org.springframework.web.servlet.ViewResolver;
public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
implements ViewResolver, Ordered, InitializingBean {
- private int order = Ordered.HIGHEST_PRECEDENCE;
-
private ContentNegotiationManager contentNegotiationManager;
private final ContentNegotiationManagerFactoryBean cnmFactoryBean = new ContentNegotiationManagerFactoryBean();
@@ -99,15 +97,8 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
private List viewResolvers;
+ private int order = Ordered.HIGHEST_PRECEDENCE;
- public void setOrder(int order) {
- this.order = order;
- }
-
- @Override
- public int getOrder() {
- return this.order;
- }
/**
* Set the {@link ContentNegotiationManager} to use to determine requested media types.
@@ -171,6 +162,15 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
return Collections.unmodifiableList(this.viewResolvers);
}
+ public void setOrder(int order) {
+ this.order = order;
+ }
+
+ @Override
+ public int getOrder() {
+ return this.order;
+ }
+
@Override
protected void initServletContext(ServletContext servletContext) {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerConfig.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerConfig.java
index b6a6bb7ed7c..00b0be6392b 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerConfig.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -33,7 +33,7 @@ import freemarker.template.Configuration;
public interface FreeMarkerConfig {
/**
- * Return the FreeMarker Configuration object for the current
+ * Return the FreeMarker {@link Configuration} object for the current
* web application context.
* A FreeMarker Configuration object may be used to set FreeMarker
* properties and shared objects, and allows to retrieve templates.
@@ -42,7 +42,7 @@ public interface FreeMarkerConfig {
Configuration getConfiguration();
/**
- * Returns the {@link TaglibFactory} used to enable JSP tags to be
+ * Return the {@link TaglibFactory} used to enable JSP tags to be
* accessed from FreeMarker templates.
*/
TaglibFactory getTaglibFactory();
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java
index 00e678f136a..455140fd1c0 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -199,24 +199,25 @@ public class FreeMarkerView extends AbstractTemplateView {
*/
@Override
public boolean checkResource(Locale locale) throws Exception {
+ String url = getUrl();
try {
// Check that we can get the template, even if we might subsequently get it again.
- getTemplate(getUrl(), locale);
+ getTemplate(url, locale);
return true;
}
catch (FileNotFoundException ex) {
if (logger.isDebugEnabled()) {
- logger.debug("No FreeMarker view found for URL: " + getUrl());
+ logger.debug("No FreeMarker view found for URL: " + url);
}
return false;
}
catch (ParseException ex) {
throw new ApplicationContextException(
- "Failed to parse FreeMarker template for URL [" + getUrl() + "]", ex);
+ "Failed to parse FreeMarker template for URL [" + url + "]", ex);
}
catch (IOException ex) {
throw new ApplicationContextException(
- "Could not load FreeMarker template for URL [" + getUrl() + "]", ex);
+ "Could not load FreeMarker template for URL [" + url + "]", ex);
}
}
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/GroovyMarkupConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/GroovyMarkupConfigurer.java
index 69a5cb36efe..2d242a8f090 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/GroovyMarkupConfigurer.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/groovy/GroovyMarkupConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -118,7 +118,7 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
}
public MarkupTemplateEngine getTemplateEngine() {
- return templateEngine;
+ return this.templateEngine;
}
@Override
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java
index 6e2d84465b1..b091d610e67 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java
@@ -55,7 +55,7 @@ import org.springframework.web.servlet.view.AbstractUrlBasedView;
* {@link ScriptTemplateConfig} bean in the web application context and using
* it to obtain the configured properties.
*
- *
Nashorn Javascript engine requires Java 8+, and may require setting the
+ *
The Nashorn JavaScript engine requires Java 8+ and may require setting the
* {@code sharedEngine} property to {@code false} in order to run properly. See
* {@link ScriptTemplateConfigurer#setSharedEngine(Boolean)} for more details.
*
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/NativeWebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/NativeWebSocketSession.java
index ef703279129..f801d92ecba 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/adapter/NativeWebSocketSession.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/adapter/NativeWebSocketSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -28,15 +28,15 @@ import org.springframework.web.socket.WebSocketSession;
public interface NativeWebSocketSession extends WebSocketSession {
/**
- * Return the underlying native WebSocketSession, if available.
- * @return the native session or {@code null}
+ * Return the underlying native WebSocketSession.
*/
Object getNativeSession();
/**
* Return the underlying native WebSocketSession, if available.
* @param requiredType the required type of the session
- * @return the native session of the required type or {@code null}
+ * @return the native session of the required type,
+ * or {@code null} if not available
*/
T getNativeSession(Class requiredType);
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java
index bdfd8f06336..7bd84604bad 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -89,7 +89,7 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
}
/**
- * @return the configured origin.
+ * Return the configured origin.
*/
public String getOrigin() {
return this.headers.getOrigin();
@@ -151,7 +151,9 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
@Override
protected void closeConnection() throws Exception {
- this.webSocketSession.close();
+ if (this.webSocketSession != null) {
+ this.webSocketSession.close();
+ }
}
@Override
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java
index db7032af782..d0cd29afa59 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/jetty/JettyWebSocketClient.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -84,9 +84,8 @@ public class JettyWebSocketClient extends AbstractWebSocketClient implements Lif
/**
* Set an {@link AsyncListenableTaskExecutor} to use when opening connections.
- * If this property is set to {@code null}, calls to any of the
+ * If this property is set to {@code null}, calls to any of the
* {@code doHandshake} methods will block until the connection is established.
- *
* By default an instance of {@code SimpleAsyncTaskExecutor} is used.
*/
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) {
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java
index 0f5bd934e8c..3e64830aa9c 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -106,11 +106,11 @@ public class WebSocketMessageBrokerStats {
}
private ScheduledFuture> initLoggingTask(long initialDelay) {
- if (logger.isInfoEnabled() && this.loggingPeriod > 0) {
+ if (this.loggingPeriod > 0 && logger.isInfoEnabled()) {
return this.sockJsTaskScheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
- logger.info(WebSocketMessageBrokerStats.this.toString());
+ logger.info(WebSocketMessageBrokerStats.this);
}
}, initialDelay, this.loggingPeriod, TimeUnit.MILLISECONDS);
}
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java
index 101296b2a0b..8827f2cd0e0 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -31,9 +31,9 @@ import org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsSe
import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
/**
- * A helper class for configuring SockJS fallback options, typically used indirectly, in
- * conjunction with {@link org.springframework.web.socket.config.annotation.EnableWebSocket @EnableWebSocket} and
- * {@link WebSocketConfigurer}.
+ * A helper class for configuring SockJS fallback options for use with an
+ * {@link org.springframework.web.socket.config.annotation.EnableWebSocket} and
+ * {@link WebSocketConfigurer} setup.
*
* @author Rossen Stoyanchev
* @since 4.0
@@ -264,12 +264,11 @@ public class SockJsServiceRegistration {
if (this.webSocketEnabled != null) {
service.setWebSocketEnabled(this.webSocketEnabled);
}
- if (this.allowedOrigins != null) {
- service.setAllowedOrigins(this.allowedOrigins);
- }
if (this.suppressCors != null) {
service.setSuppressCors(this.suppressCors);
}
+ service.setAllowedOrigins(this.allowedOrigins);
+
if (this.messageCodec != null) {
service.setMessageCodec(this.messageCodec);
}
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java
index 56582796b66..0ba5f488af7 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -16,7 +16,9 @@
package org.springframework.web.socket.config.annotation;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
@@ -32,13 +34,11 @@ import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler
import org.springframework.web.socket.sockjs.SockJsService;
import org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler;
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
-
-import java.util.ArrayList;
-import java.util.List;
/**
* An abstract base class for configuring STOMP over WebSocket/SockJS endpoints.
*
* @author Rossen Stoyanchev
+ * @author Juergen Hoeller
* @since 4.0
*/
public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketEndpointRegistration {
@@ -55,7 +55,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
private final List allowedOrigins = new ArrayList();
- private StompSockJsServiceRegistration registration;
+ private SockJsServiceRegistration registration;
public WebMvcStompWebSocketEndpointRegistration(String[] paths, WebSocketHandler webSocketHandler,
@@ -69,6 +69,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
this.sockJsTaskScheduler = sockJsTaskScheduler;
}
+
@Override
public StompWebSocketEndpointRegistration setHandshakeHandler(HandshakeHandler handshakeHandler) {
Assert.notNull(handshakeHandler, "'handshakeHandler' must not be null");
@@ -95,14 +96,14 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
@Override
public SockJsServiceRegistration withSockJS() {
- this.registration = new StompSockJsServiceRegistration(this.sockJsTaskScheduler);
+ this.registration = new SockJsServiceRegistration(this.sockJsTaskScheduler);
HandshakeInterceptor[] interceptors = getInterceptors();
if (interceptors.length > 0) {
this.registration.setInterceptors(interceptors);
}
if (this.handshakeHandler != null) {
- WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler);
- this.registration.setTransportHandlerOverrides(transportHandler);
+ WebSocketTransportHandler handler = new WebSocketTransportHandler(this.handshakeHandler);
+ this.registration.setTransportHandlerOverrides(handler);
}
if (!this.allowedOrigins.isEmpty()) {
this.registration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
@@ -146,16 +147,4 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
return mappings;
}
-
- private static class StompSockJsServiceRegistration extends SockJsServiceRegistration {
-
- public StompSockJsServiceRegistration(TaskScheduler defaultTaskScheduler) {
- super(defaultTaskScheduler);
- }
-
- protected SockJsService getSockJsService() {
- return super.getSockJsService();
- }
- }
-
}
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java
index 417ad5d642f..b2055e3fac1 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -134,7 +134,7 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
MappingJackson2MessageConverter messageConverter = super.createJacksonConverter();
// Use Jackson builder in order to have JSR-310 and Joda-Time modules registered automatically
messageConverter.setObjectMapper(Jackson2ObjectMapperBuilder.json()
- .applicationContext(this.getApplicationContext()).build());
+ .applicationContext(getApplicationContext()).build());
return messageConverter;
}
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionSubscribeEvent.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionSubscribeEvent.java
index 5a3498f7bd2..c2140f11b85 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionSubscribeEvent.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionSubscribeEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -16,7 +16,6 @@
package org.springframework.web.socket.messaging;
-
import java.security.Principal;
import org.springframework.messaging.Message;
@@ -31,7 +30,6 @@ import org.springframework.messaging.Message;
@SuppressWarnings("serial")
public class SessionSubscribeEvent extends AbstractSubProtocolEvent {
-
public SessionSubscribeEvent(Object source, Message message) {
super(source, message);
}
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionUnsubscribeEvent.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionUnsubscribeEvent.java
index cd3352716fa..974e73e5b93 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionUnsubscribeEvent.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SessionUnsubscribeEvent.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -16,7 +16,6 @@
package org.springframework.web.socket.messaging;
-
import java.security.Principal;
import org.springframework.messaging.Message;
@@ -31,7 +30,6 @@ import org.springframework.messaging.Message;
@SuppressWarnings("serial")
public class SessionUnsubscribeEvent extends AbstractSubProtocolEvent {
-
public SessionUnsubscribeEvent(Object source, Message message) {
super(source, message);
}
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketAnnotationMethodMessageHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketAnnotationMethodMessageHandler.java
index 9f1c4a69a83..959e3e9e915 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketAnnotationMethodMessageHandler.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketAnnotationMethodMessageHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -19,6 +19,7 @@ package org.springframework.web.socket.messaging;
import java.util.ArrayList;
import java.util.List;
+import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
@@ -28,7 +29,6 @@ import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
import org.springframework.web.method.ControllerAdviceBean;
-
/**
* A sub-class of {@link SimpAnnotationMethodMessageHandler} to provide support
* for {@link org.springframework.web.bind.annotation.ControllerAdvice
@@ -39,7 +39,6 @@ import org.springframework.web.method.ControllerAdviceBean;
*/
public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMethodMessageHandler {
-
public WebSocketAnnotationMethodMessageHandler(SubscribableChannel clientInChannel,
MessageChannel clientOutChannel, SimpMessageSendingOperations brokerTemplate) {
@@ -54,13 +53,14 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
}
private void initControllerAdviceCache() {
- if (getApplicationContext() == null) {
+ ApplicationContext context = getApplicationContext();
+ if (context == null) {
return;
}
if (logger.isDebugEnabled()) {
- logger.debug("Looking for @MessageExceptionHandler mappings: " + getApplicationContext());
+ logger.debug("Looking for @MessageExceptionHandler mappings: " + context);
}
- List beans = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext());
+ List beans = ControllerAdviceBean.findAnnotatedBeans(context);
AnnotationAwareOrderComparator.sort(beans);
initMessagingAdviceCache(MessagingControllerAdviceBean.createFromList(beans));
}
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServletServerContainerFactoryBean.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServletServerContainerFactoryBean.java
index 7fe861464f3..909385a7def 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServletServerContainerFactoryBean.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServletServerContainerFactoryBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -63,7 +63,7 @@ public class ServletServerContainerFactoryBean
this.asyncSendTimeout = timeoutInMillis;
}
- public long getAsyncSendTimeout() {
+ public Long getAsyncSendTimeout() {
return this.asyncSendTimeout;
}
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java
index e32ff263c8b..6f9e37bdb7d 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java
@@ -309,15 +309,19 @@ public abstract class AbstractClientSockJsSession implements WebSocketSession {
}
public void afterTransportClosed(CloseStatus closeStatus) {
- this.closeStatus = (this.closeStatus != null ? this.closeStatus : closeStatus);
- Assert.state(this.closeStatus != null, "CloseStatus not available");
+ CloseStatus cs = this.closeStatus;
+ if (cs == null) {
+ cs = closeStatus;
+ this.closeStatus = closeStatus;
+ }
+ Assert.state(cs != null, "CloseStatus not available");
if (logger.isDebugEnabled()) {
- logger.debug("Transport closed with " + this.closeStatus + " in " + this);
+ logger.debug("Transport closed with " + cs + " in " + this);
}
this.state = State.CLOSED;
try {
- this.webSocketHandler.afterConnectionClosed(this, this.closeStatus);
+ this.webSocketHandler.afterConnectionClosed(this, cs);
}
catch (Throwable ex) {
logger.error("WebSocketHandler.afterConnectionClosed threw an exception", ex);
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java
index 99949da1c05..511216ae812 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java
index 9d03c1fd16f..bff20ddd5d9 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/WebSocketClientSockJsSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -16,7 +16,6 @@
package org.springframework.web.socket.sockjs.client;
-
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.List;
@@ -57,12 +56,7 @@ public class WebSocketClientSockJsSession extends AbstractClientSockJsSession im
@SuppressWarnings("unchecked")
@Override
public T getNativeSession(Class requiredType) {
- if (requiredType != null) {
- if (requiredType.isInstance(this.webSocketSession)) {
- return (T) this.webSocketSession;
- }
- }
- return null;
+ return (requiredType == null || requiredType.isInstance(this.webSocketSession) ? (T) this.webSocketSession : null);
}
@Override
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java
index 227d4b01d37..654fcd3d93c 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java
@@ -121,8 +121,8 @@ public abstract class AbstractSockJsSession implements SockJsSession {
public AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler,
Map attributes) {
- Assert.notNull(id, "SessionId must not be null");
- Assert.notNull(config, "SockJsConfig must not be null");
+ Assert.notNull(id, "Session id must not be null");
+ Assert.notNull(config, "SockJsServiceConfig must not be null");
Assert.notNull(handler, "WebSocketHandler must not be null");
this.id = id;
diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java
index b3c8c3ca40e..733b6c303d8 100644
--- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java
+++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -140,7 +140,7 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
@Override
public Object getNativeSession() {
return (this.webSocketSession instanceof NativeWebSocketSession ?
- ((NativeWebSocketSession) this.webSocketSession).getNativeSession() : null);
+ ((NativeWebSocketSession) this.webSocketSession).getNativeSession() : this.webSocketSession);
}
@Override
@@ -190,7 +190,9 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
tryCloseWithSockJsTransportError(ex, CloseStatus.BAD_DATA);
return;
}
- delegateMessages(messages);
+ if (messages != null) {
+ delegateMessages(messages);
+ }
}
@Override
@@ -226,7 +228,9 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
synchronized (this.disconnectLock) {
if (isActive()) {
this.disconnected = true;
- this.webSocketSession.close(status);
+ if (this.webSocketSession != null) {
+ this.webSocketSession.close(status);
+ }
}
}
}