diff --git a/build.gradle b/build.gradle index 2481d7fe1f9..6a8bae20331 100644 --- a/build.gradle +++ b/build.gradle @@ -190,14 +190,13 @@ configure(allprojects) { project -> "http://docs.jboss.org/jbossas/javadoc/4.0.5/connector/", "http://docs.jboss.org/jbossas/javadoc/7.1.2.Final/", "http://commons.apache.org/proper/commons-lang/javadocs/api-2.5/", - "http://commons.apache.org/proper/commons-codec/apidocs/", "http://commons.apache.org/proper/commons-dbcp/apidocs/", "http://tiles.apache.org/tiles-request/apidocs/", "http://tiles.apache.org/framework/apidocs/", "http://www.eclipse.org/aspectj/doc/released/aspectj5rt-api/", "http://ehcache.org/apidocs/${ehcacheVersion}", "http://ehcache.org/apidocs/${ehcache3Version}", - "http://quartz-scheduler.org/api/2.2.0/", + "http://quartz-scheduler.org/api/2.2.1/", "http://fasterxml.github.io/jackson-core/javadoc/2.7/", "http://fasterxml.github.io/jackson-databind/javadoc/2.7/", "http://fasterxml.github.io/jackson-dataformat-xml/javadoc/2.7/", @@ -347,7 +346,6 @@ project("spring-core") { compile(files(cglibRepackJar)) compile(files(objenesisRepackJar)) compile("commons-logging:commons-logging:1.2") - optional("commons-codec:commons-codec:1.10") optional("org.aspectj:aspectjweaver:${aspectjVersion}") optional("net.sf.jopt-simple:jopt-simple:5.0.2") optional("log4j:log4j:${log4jVersion}") @@ -1116,6 +1114,8 @@ configure(rootProject) { doFirst { classpath = files( + // ensure Servlet 3.x has precedence on the javadoc classpath + project(":spring-webmvc").sourceSets.main.compileClasspath.files.find { it =~ "servlet-api" }, // ensure the javadoc process can resolve types compiled from .aj sources project(":spring-aspects").sourceSets.main.output ) diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java b/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java index 7fa2b872691..c08fd7443f2 100644 --- a/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java +++ b/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java @@ -46,7 +46,7 @@ public interface MethodInterceptor extends Interceptor { * after the invocation. Polite implementations would certainly * like to invoke {@link Joinpoint#proceed()}. * @param invocation the method invocation joinpoint - * @return the result of the call to {@link Joinpoint#proceed(); + * @return the result of the call to {@link Joinpoint#proceed()}; * might be intercepted by the interceptor * @throws Throwable if the interceptors or the target object * throws an exception diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java index 28917436f08..a0ee6279763 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionAspectSupport.java @@ -38,8 +38,6 @@ import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.support.TaskExecutorAdapter; -import org.springframework.lang.UsesJava8; -import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.concurrent.ListenableFuture; @@ -70,11 +68,6 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { public static final String DEFAULT_TASK_EXECUTOR_BEAN_NAME = "taskExecutor"; - // Java 8's CompletableFuture type present? - private static final boolean completableFuturePresent = ClassUtils.isPresent( - "java.util.concurrent.CompletableFuture", AsyncExecutionInterceptor.class.getClassLoader()); - - protected final Log logger = LogFactory.getLog(getClass()); private final Map executors = new ConcurrentHashMap(16); @@ -257,13 +250,20 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * @return the execution result (potentially a corresponding {@link Future} handle) */ protected Object doSubmit(Callable task, AsyncTaskExecutor executor, Class returnType) { - if (completableFuturePresent) { - Future result = CompletableFutureDelegate.processCompletableFuture(returnType, task, executor); - if (result != null) { - return result; - } + if (CompletableFuture.class.isAssignableFrom(returnType)) { + return CompletableFuture.supplyAsync(new Supplier() { + @Override + public Object get() { + try { + return task.call(); + } + catch (Throwable ex) { + throw new CompletionException(ex); + } + } + }, executor); } - if (ListenableFuture.class.isAssignableFrom(returnType)) { + else if (ListenableFuture.class.isAssignableFrom(returnType)) { return ((AsyncListenableTaskExecutor) executor).submitListenable(task); } else if (Future.class.isAssignableFrom(returnType)) { @@ -303,29 +303,4 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { } } - - /** - * Inner class to avoid a hard dependency on Java 8. - */ - @UsesJava8 - private static class CompletableFutureDelegate { - - public static Future processCompletableFuture(Class returnType, final Callable task, Executor executor) { - if (!CompletableFuture.class.isAssignableFrom(returnType)) { - return null; - } - return CompletableFuture.supplyAsync(new Supplier() { - @Override - public T get() { - try { - return task.call(); - } - catch (Throwable ex) { - throw new CompletionException(ex); - } - } - }, executor); - } - } - } diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java index 08e4ae39fef..ff59001b875 100644 --- a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java @@ -38,9 +38,7 @@ import org.springframework.core.ResolvableType; import org.springframework.core.convert.ConversionException; import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.UsesJava8; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -75,19 +73,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA */ private static final Log logger = LogFactory.getLog(AbstractNestablePropertyAccessor.class); - private static Class javaUtilOptionalClass = null; - - static { - try { - javaUtilOptionalClass = - ClassUtils.forName("java.util.Optional", AbstractNestablePropertyAccessor.class.getClassLoader()); - } - catch (ClassNotFoundException ex) { - // Java 8 not available - Optional references simply not supported then. - } - } - - private int autoGrowCollectionLimit = Integer.MAX_VALUE; Object wrappedObject; @@ -202,13 +187,8 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA * @param rootObject the root object at the top of the path */ public void setWrappedInstance(Object object, String nestedPath, Object rootObject) { - Assert.notNull(object, "Target object must not be null"); - if (object.getClass() == javaUtilOptionalClass) { - this.wrappedObject = OptionalUnwrapper.unwrap(object); - } - else { - this.wrappedObject = object; - } + this.wrappedObject = ObjectUtils.unwrapOptional(object); + Assert.notNull(this.wrappedObject, "Target object must not be null"); this.nestedPath = (nestedPath != null ? nestedPath : ""); this.rootObject = (!"".equals(this.nestedPath) ? rootObject : this.wrappedObject); this.nestedPropertyAccessors = null; @@ -834,7 +814,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA PropertyTokenHolder tokens = getPropertyNameTokens(nestedProperty); String canonicalName = tokens.canonicalName; Object value = getPropertyValue(tokens); - if (value == null || (value.getClass() == javaUtilOptionalClass && OptionalUnwrapper.isEmpty(value))) { + if (value == null || (value instanceof Optional && !((Optional) value).isPresent())) { if (isAutoGrowNestedPaths()) { value = setDefaultValue(tokens); } @@ -845,8 +825,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA // Lookup cached sub-PropertyAccessor, create new one if not found. AbstractNestablePropertyAccessor nestedPa = this.nestedPropertyAccessors.get(canonicalName); - if (nestedPa == null || nestedPa.getWrappedInstance() != - (value.getClass() == javaUtilOptionalClass ? OptionalUnwrapper.unwrap(value) : value)) { + if (nestedPa == null || nestedPa.getWrappedInstance() != ObjectUtils.unwrapOptional(value)) { if (logger.isTraceEnabled()) { logger.trace("Creating new nested " + getClass().getSimpleName() + " for property '" + canonicalName + "'"); } @@ -1037,24 +1016,4 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA public String[] keys; } - - /** - * Inner class to avoid a hard dependency on Java 8. - */ - @UsesJava8 - private static class OptionalUnwrapper { - - public static Object unwrap(Object optionalObject) { - Optional optional = (Optional) optionalObject; - Assert.isTrue(optional.isPresent(), "Optional value must be present"); - Object result = optional.get(); - Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported"); - return result; - } - - public static boolean isEmpty(Object optionalObject) { - return !((Optional) optionalObject).isPresent(); - } - } - } diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java index 9928530dbd4..1d75c87a369 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java @@ -24,6 +24,7 @@ import java.lang.reflect.Modifier; import java.util.Collection; import java.util.Iterator; import java.util.Map; +import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,20 +55,6 @@ class TypeConverterDelegate { private static final Log logger = LogFactory.getLog(TypeConverterDelegate.class); - /** Java 8's java.util.Optional.empty() instance */ - private static Object javaUtilOptionalEmpty = null; - - static { - try { - Class clazz = ClassUtils.forName("java.util.Optional", TypeConverterDelegate.class.getClassLoader()); - javaUtilOptionalEmpty = ClassUtils.getMethod(clazz, "empty").invoke(null); - } - catch (Exception ex) { - // Java 8 not available - conversion to Optional not supported then. - } - } - - private final PropertyEditorRegistrySupport propertyEditorRegistry; private final Object targetObject; @@ -269,8 +256,8 @@ class TypeConverterDelegate { } else { // convertedValue == null - if (javaUtilOptionalEmpty != null && requiredType.equals(javaUtilOptionalEmpty.getClass())) { - convertedValue = javaUtilOptionalEmpty; + if (requiredType == Optional.class) { + convertedValue = Optional.empty(); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 6205fa69cfe..557407e0f79 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -69,7 +69,6 @@ import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.core.OrderComparator; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.UsesJava8; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CompositeIterator; @@ -114,18 +113,9 @@ import org.springframework.util.StringUtils; public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable { - private static Class javaUtilOptionalClass = null; - private static Class javaxInjectProviderClass = null; static { - try { - javaUtilOptionalClass = - ClassUtils.forName("java.util.Optional", DefaultListableBeanFactory.class.getClassLoader()); - } - catch (ClassNotFoundException ex) { - // Java 8 not available - Optional references simply not supported then. - } try { javaxInjectProviderClass = ClassUtils.forName("javax.inject.Provider", DefaultListableBeanFactory.class.getClassLoader()); @@ -1002,8 +992,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto Set autowiredBeanNames, TypeConverter typeConverter) throws BeansException { descriptor.initParameterNameDiscovery(getParameterNameDiscoverer()); - if (descriptor.getDependencyType().equals(javaUtilOptionalClass)) { - return new OptionalDependencyFactory().createOptionalDependency(descriptor, beanName); + if (descriptor.getDependencyType() == Optional.class) { + return createOptionalDependency(descriptor, beanName); } else if (ObjectFactory.class == descriptor.getDependencyType() || ObjectProvider.class == descriptor.getDependencyType()) { @@ -1403,6 +1393,23 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto "Dependency annotations: " + ObjectUtils.nullSafeToString(descriptor.getAnnotations())); } + private Optional createOptionalDependency(DependencyDescriptor descriptor, String beanName, final Object... args) { + DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) { + @Override + public boolean isRequired() { + return false; + } + + @Override + public Object resolveCandidate(String beanName, BeanFactory beanFactory) { + return (!ObjectUtils.isEmpty(args) ? beanFactory.getBean(beanName, args) : + super.resolveCandidate(beanName, beanFactory)); + } + }; + descriptorToUse.increaseNestingLevel(); + return Optional.ofNullable(doResolveDependency(descriptorToUse, beanName, null, null)); + } + @Override public String toString() { @@ -1466,30 +1473,6 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } - /** - * Separate inner class for avoiding a hard dependency on the {@code javax.inject} API. - */ - @UsesJava8 - private class OptionalDependencyFactory { - - public Object createOptionalDependency(DependencyDescriptor descriptor, String beanName, final Object... args) { - DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) { - @Override - public boolean isRequired() { - return false; - } - @Override - public Object resolveCandidate(String beanName, BeanFactory beanFactory) { - return (!ObjectUtils.isEmpty(args) ? beanFactory.getBean(beanName, args) : - super.resolveCandidate(beanName, beanFactory)); - } - }; - descriptorToUse.increaseNestingLevel(); - return Optional.ofNullable(doResolveDependency(descriptorToUse, beanName, null, null)); - } - } - - /** * Serializable ObjectFactory/ObjectProvider for lazy resolution of a dependency. */ @@ -1504,14 +1487,14 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto public DependencyObjectProvider(DependencyDescriptor descriptor, String beanName) { this.descriptor = new DependencyDescriptor(descriptor); this.descriptor.increaseNestingLevel(); - this.optional = this.descriptor.getDependencyType().equals(javaUtilOptionalClass); + this.optional = (this.descriptor.getDependencyType() == Optional.class); this.beanName = beanName; } @Override public Object getObject() throws BeansException { if (this.optional) { - return new OptionalDependencyFactory().createOptionalDependency(this.descriptor, this.beanName); + return createOptionalDependency(this.descriptor, this.beanName); } else { return doResolveDependency(this.descriptor, this.beanName, null, null); @@ -1521,7 +1504,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override public Object getObject(final Object... args) throws BeansException { if (this.optional) { - return new OptionalDependencyFactory().createOptionalDependency(this.descriptor, this.beanName, args); + return createOptionalDependency(this.descriptor, this.beanName, args); } else { DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) { @@ -1537,7 +1520,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override public Object getIfAvailable() throws BeansException { if (this.optional) { - return new OptionalDependencyFactory().createOptionalDependency(this.descriptor, this.beanName); + return createOptionalDependency(this.descriptor, this.beanName); } else { DependencyDescriptor descriptorToUse = new DependencyDescriptor(descriptor) { @@ -1563,7 +1546,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } }; if (this.optional) { - return new OptionalDependencyFactory().createOptionalDependency(descriptorToUse, this.beanName); + return createOptionalDependency(descriptorToUse, this.beanName); } else { return doResolveDependency(descriptorToUse, this.beanName, null, null); diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ZoneIdEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ZoneIdEditor.java index 71b3bf7c403..eacfcd72c32 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ZoneIdEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ZoneIdEditor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,8 +19,6 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; import java.time.ZoneId; -import org.springframework.lang.UsesJava8; - /** * Editor for {@code java.time.ZoneId}, translating zone ID Strings into {@code ZoneId} * objects. Exposes the {@code TimeZone} ID as a text representation. @@ -30,7 +28,6 @@ import org.springframework.lang.UsesJava8; * @see java.time.ZoneId * @see TimeZoneEditor */ -@UsesJava8 public class ZoneIdEditor extends PropertyEditorSupport { @Override diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java index d9fcec586a4..2fff82889c7 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java @@ -22,7 +22,6 @@ import java.util.function.Function; import com.github.benmanes.caffeine.cache.LoadingCache; import org.springframework.cache.support.AbstractValueAdaptingCache; -import org.springframework.lang.UsesJava8; import org.springframework.util.Assert; /** @@ -36,7 +35,6 @@ import org.springframework.util.Assert; * @author Stephane Nicoll * @since 4.3 */ -@UsesJava8 public class CaffeineCache extends AbstractValueAdaptingCache { private final String name; diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/package-info.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/package-info.java index 4291b2deae8..edb951a4ce5 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/package-info.java @@ -7,6 +7,6 @@ *

Note: EhCache 3.x lives in a different package namespace * and is not covered by the traditional support classes here. * Instead, consider using it through JCache (JSR-107), with - * Spring's support in {@link org.springframework.cache.jcache}. + * Spring's support in {@code org.springframework.cache.jcache}. */ package org.springframework.cache.ehcache; diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java index f99b40d756e..f7f6fa4ec7c 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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. @@ -52,7 +52,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector result = new ArrayList(); result.add(AutoProxyRegistrar.class.getName()); result.add(ProxyCachingConfiguration.class.getName()); - if (jsr107Present && jCacheImplPresent) { + if (jsr107Present && jcacheImplPresent) { result.add(PROXY_JCACHE_CONFIGURATION_CLASS); } return result.toArray(new String[result.size()]); @@ -94,7 +94,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector result = new ArrayList(); result.add(CACHE_ASPECT_CONFIGURATION_CLASS_NAME); - if (jsr107Present && jCacheImplPresent) { + if (jsr107Present && jcacheImplPresent) { result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME); } return result.toArray(new String[result.size()]); 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 4ea5ccad0aa..d9f90dc2f14 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-2014 the original author or authors. + * Copyright 2002-2016 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,11 +60,10 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser private static final String JCACHE_ASPECT_CLASS_NAME = "org.springframework.cache.aspectj.JCacheCacheAspect"; - private static final boolean jsr107Present = ClassUtils.isPresent( "javax.cache.Cache", AnnotationDrivenCacheBeanDefinitionParser.class.getClassLoader()); - private static final boolean jCacheImplPresent = ClassUtils.isPresent( + private static final boolean jcacheImplPresent = ClassUtils.isPresent( "org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource", AnnotationDrivenCacheBeanDefinitionParser.class.getClassLoader()); @@ -91,7 +90,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser private void registerCacheAspect(Element element, ParserContext parserContext) { SpringCachingConfigurer.registerCacheAspect(element, parserContext); - if (jsr107Present && jCacheImplPresent) { // Register JCache aspect + if (jsr107Present && jcacheImplPresent) { JCacheCachingConfigurer.registerCacheAspect(element, parserContext); } } @@ -99,7 +98,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser private void registerCacheAdvisor(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); SpringCachingConfigurer.registerCacheAdvisor(element, parserContext); - if (jsr107Present && jCacheImplPresent) { // Register JCache advisor + if (jsr107Present && jcacheImplPresent) { JCacheCachingConfigurer.registerCacheAdvisor(element, parserContext); } } 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 2de8bd8f5c3..6cd19d5089c 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 @@ -43,7 +43,6 @@ import org.springframework.cache.CacheManager; import org.springframework.context.ApplicationContext; import org.springframework.context.expression.AnnotatedElementKey; import org.springframework.expression.EvaluationContext; -import org.springframework.lang.UsesJava8; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -81,18 +80,6 @@ import org.springframework.util.StringUtils; public abstract class CacheAspectSupport extends AbstractCacheInvoker implements BeanFactoryAware, InitializingBean, SmartInitializingSingleton { - private static Class javaUtilOptionalClass = null; - - static { - try { - javaUtilOptionalClass = - ClassUtils.forName("java.util.Optional", CacheAspectSupport.class.getClassLoader()); - } - catch (ClassNotFoundException ex) { - // Java 8 not available - Optional references simply not supported then. - } - } - protected final Log logger = LogFactory.getLog(getClass()); private final Map metadataCache = @@ -401,9 +388,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker if (cacheHit != null && cachePutRequests.isEmpty() && !hasCachePut(contexts)) { // If there are no put requests, just use the cache hit cacheValue = cacheHit.get(); - if (method.getReturnType() == javaUtilOptionalClass && - (cacheValue == null || cacheValue.getClass() != javaUtilOptionalClass)) { - returnValue = OptionalUnwrapper.wrap(cacheValue); + if (method.getReturnType() == Optional.class && + (cacheValue == null || cacheValue.getClass() != Optional.class)) { + returnValue = Optional.ofNullable(cacheValue); } else { returnValue = cacheValue; @@ -412,12 +399,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker else { // Invoke the method if we don't have a cache hit returnValue = invokeOperation(invoker); - if (returnValue != null && returnValue.getClass() == javaUtilOptionalClass) { - cacheValue = OptionalUnwrapper.unwrap(returnValue); - } - else { - cacheValue = returnValue; - } + cacheValue = ObjectUtils.unwrapOptional(returnValue); } // Collect any explicit @CachePuts @@ -828,26 +810,4 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker } } - - /** - * Inner class to avoid a hard dependency on Java 8. - */ - @UsesJava8 - private static class OptionalUnwrapper { - - public static Object unwrap(Object optionalObject) { - Optional optional = (Optional) optionalObject; - if (!optional.isPresent()) { - return null; - } - Object result = optional.get(); - Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported"); - return result; - } - - public static Object wrap(Object value) { - return Optional.ofNullable(value); - } - } - } diff --git a/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java b/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java index a54ccab47da..dd3ca6a10c4 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java +++ b/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.DecoratingClassLoader; import org.springframework.core.OverridingClassLoader; import org.springframework.core.SmartClassLoader; -import org.springframework.lang.UsesJava7; import org.springframework.util.ReflectionUtils; /** @@ -37,13 +36,10 @@ import org.springframework.util.ReflectionUtils; * @see AbstractApplicationContext * @see org.springframework.beans.factory.config.ConfigurableBeanFactory#setTempClassLoader */ -@UsesJava7 class ContextTypeMatchClassLoader extends DecoratingClassLoader implements SmartClassLoader { static { - if (parallelCapableClassLoaderAvailable) { - ClassLoader.registerAsParallelCapable(); - } + ClassLoader.registerAsParallelCapable(); } diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContext.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContext.java index a65754ab21d..4ef23be208a 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContext.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,6 @@ import java.util.TimeZone; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; -import org.springframework.lang.UsesJava8; /** * A context that holds user-specific java.time (JSR-310) settings @@ -35,7 +34,6 @@ import org.springframework.lang.UsesJava8; * @since 4.0 * @see DateTimeContextHolder */ -@UsesJava8 public class DateTimeContext { private Chronology chronology; diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContextHolder.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContextHolder.java index e34149e3894..276cbff3a64 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContextHolder.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeContextHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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.time.format.DateTimeFormatter; import java.util.Locale; import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.UsesJava8; /** * A holder for a thread-local user {@link DateTimeContext}. @@ -28,7 +27,6 @@ import org.springframework.lang.UsesJava8; * @author Juergen Hoeller * @since 4.0 */ -@UsesJava8 public final class DateTimeContextHolder { private static final ThreadLocal dateTimeContextHolder = diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java index fe5a1162d31..1d73bb4a162 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ import java.util.GregorianCalendar; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterRegistry; import org.springframework.format.datetime.DateFormatterRegistrar; -import org.springframework.lang.UsesJava8; /** * Installs lower-level type converters required to integrate @@ -43,7 +42,6 @@ import org.springframework.lang.UsesJava8; * @author Juergen Hoeller * @since 4.0.1 */ -@UsesJava8 final class DateTimeConverters { /** @@ -86,7 +84,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class LocalDateTimeToLocalDateConverter implements Converter { @Override @@ -96,7 +93,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class LocalDateTimeToLocalTimeConverter implements Converter { @Override @@ -106,7 +102,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class ZonedDateTimeToLocalDateConverter implements Converter { @Override @@ -116,7 +111,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class ZonedDateTimeToLocalTimeConverter implements Converter { @Override @@ -126,7 +120,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class ZonedDateTimeToLocalDateTimeConverter implements Converter { @Override @@ -135,7 +128,6 @@ final class DateTimeConverters { } } - @UsesJava8 private static class ZonedDateTimeToOffsetDateTimeConverter implements Converter { @Override @@ -145,7 +137,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class ZonedDateTimeToInstantConverter implements Converter { @Override @@ -156,7 +147,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class OffsetDateTimeToLocalDateConverter implements Converter { @Override @@ -166,7 +156,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class OffsetDateTimeToLocalTimeConverter implements Converter { @Override @@ -176,7 +165,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class OffsetDateTimeToLocalDateTimeConverter implements Converter { @Override @@ -186,7 +174,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class OffsetDateTimeToZonedDateTimeConverter implements Converter { @Override @@ -196,7 +183,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class OffsetDateTimeToInstantConverter implements Converter { @Override @@ -206,7 +192,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class CalendarToZonedDateTimeConverter implements Converter { @Override @@ -216,7 +201,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class CalendarToOffsetDateTimeConverter implements Converter { @Override @@ -226,7 +210,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class CalendarToLocalDateConverter implements Converter { @Override @@ -236,7 +219,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class CalendarToLocalTimeConverter implements Converter { @Override @@ -246,7 +228,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class CalendarToLocalDateTimeConverter implements Converter { @Override @@ -256,7 +237,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class CalendarToInstantConverter implements Converter { @Override @@ -267,7 +247,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class LongToInstantConverter implements Converter { @Override @@ -277,7 +256,6 @@ final class DateTimeConverters { } - @UsesJava8 private static class InstantToLongConverter implements Converter { @Override diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactory.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactory.java index fb4f50b3832..70cb9acf0eb 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactory.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactory.java @@ -22,7 +22,6 @@ import java.time.format.ResolverStyle; import java.util.TimeZone; import org.springframework.format.annotation.DateTimeFormat.ISO; -import org.springframework.lang.UsesJava8; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -44,7 +43,6 @@ import org.springframework.util.StringUtils; * @see #setDateTimeStyle * @see DateTimeFormatterFactoryBean */ -@UsesJava8 public class DateTimeFormatterFactory { private String pattern; diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterRegistrar.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterRegistrar.java index 07a65cc9607..d779976484e 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterRegistrar.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,6 @@ import java.util.Map; import org.springframework.format.FormatterRegistrar; import org.springframework.format.FormatterRegistry; import org.springframework.format.annotation.DateTimeFormat.ISO; -import org.springframework.lang.UsesJava8; /** * Configures the JSR-310 java.time formatting system for use with Spring. @@ -51,7 +50,6 @@ import org.springframework.lang.UsesJava8; * @see org.springframework.format.datetime.DateFormatterRegistrar * @see org.springframework.format.datetime.joda.DateTimeFormatterFactoryBean */ -@UsesJava8 public class DateTimeFormatterRegistrar implements FormatterRegistrar { private enum Type {DATE, TIME, DATE_TIME} diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatter.java index 57764143123..17aff811c54 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.time.Duration; import java.util.Locale; import org.springframework.format.Formatter; -import org.springframework.lang.UsesJava8; /** * {@link Formatter} implementation for a JSR-310 {@link Duration}, @@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8; * @since 4.2.4 * @see Duration#parse */ -@UsesJava8 class DurationFormatter implements Formatter { @Override diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java index 9063f82dd43..7bc9bcc8f33 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/InstantFormatter.java @@ -22,7 +22,6 @@ import java.time.format.DateTimeFormatter; import java.util.Locale; import org.springframework.format.Formatter; -import org.springframework.lang.UsesJava8; /** * {@link Formatter} implementation for a JSR-310 {@link java.time.Instant}, @@ -37,7 +36,6 @@ import org.springframework.lang.UsesJava8; * @see java.time.format.DateTimeFormatter#ISO_INSTANT * @see java.time.format.DateTimeFormatter#RFC_1123_DATE_TIME */ -@UsesJava8 public class InstantFormatter implements Formatter { @Override diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/MonthDayFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/MonthDayFormatter.java index 41a36f9fd34..288d6f936fb 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/MonthDayFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/MonthDayFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.time.MonthDay; import java.util.Locale; import org.springframework.format.Formatter; -import org.springframework.lang.UsesJava8; /** * {@link Formatter} implementation for a JSR-310 {@link MonthDay}, @@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8; * @since 4.2.4 * @see MonthDay#parse */ -@UsesJava8 class MonthDayFormatter implements Formatter { @Override diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/PeriodFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/PeriodFormatter.java index 8b13574af5e..626eaa3e6c3 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/PeriodFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/PeriodFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.time.Period; import java.util.Locale; import org.springframework.format.Formatter; -import org.springframework.lang.UsesJava8; /** * {@link Formatter} implementation for a JSR-310 {@link Period}, @@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8; * @since 4.2.4 * @see Period#parse */ -@UsesJava8 class PeriodFormatter implements Formatter { @Override diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java index 74eb3648d9f..e78584e646c 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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.time.temporal.TemporalAccessor; import java.util.Locale; import org.springframework.format.Parser; -import org.springframework.lang.UsesJava8; /** * {@link Parser} implementation for a JSR-310 {@link java.time.temporal.TemporalAccessor}, @@ -44,7 +43,6 @@ import org.springframework.lang.UsesJava8; * @see java.time.OffsetDateTime#parse(CharSequence, java.time.format.DateTimeFormatter) * @see java.time.OffsetTime#parse(CharSequence, java.time.format.DateTimeFormatter) */ -@UsesJava8 public final class TemporalAccessorParser implements Parser { private final Class temporalAccessorType; diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorPrinter.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorPrinter.java index f3c3c0c8332..dac5f1097a6 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorPrinter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorPrinter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,7 +21,6 @@ import java.time.temporal.TemporalAccessor; import java.util.Locale; import org.springframework.format.Printer; -import org.springframework.lang.UsesJava8; /** * {@link Printer} implementation for a JSR-310 {@link java.time.temporal.TemporalAccessor}, @@ -32,7 +31,6 @@ import org.springframework.lang.UsesJava8; * @see DateTimeContextHolder#getFormatter * @see java.time.format.DateTimeFormatter#format(java.time.temporal.TemporalAccessor) */ -@UsesJava8 public final class TemporalAccessorPrinter implements Printer { private final DateTimeFormatter formatter; diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/YearMonthFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/YearMonthFormatter.java index 402f77df4f3..ab72b116261 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/YearMonthFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/YearMonthFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.time.YearMonth; import java.util.Locale; import org.springframework.format.Formatter; -import org.springframework.lang.UsesJava8; /** * {@link Formatter} implementation for a JSR-310 {@link YearMonth}, @@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8; * @since 4.2.4 * @see YearMonth#parse */ -@UsesJava8 class YearMonthFormatter implements Formatter { @Override diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaver.java index ac807eee996..6ed83b3ce03 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaver.java @@ -52,9 +52,8 @@ import org.springframework.util.ReflectionUtils; * web application). There is no direct API dependency between this LoadTimeWeaver * adapter and the underlying ClassLoader, just a 'loose' method contract. * - *

This is the LoadTimeWeaver to use in combination with Spring's - * {@link org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader} - * for Tomcat 5.0+ as well as with the Resin application server version 3.1+. + *

This is the LoadTimeWeaver to use e.g. with the Resin application server + * version 3.1+. * * @author Costin Leau * @author Juergen Hoeller @@ -62,7 +61,6 @@ import org.springframework.util.ReflectionUtils; * @see #addTransformer(java.lang.instrument.ClassFileTransformer) * @see #getThrowawayClassLoader() * @see SimpleThrowawayClassLoader - * @see org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader */ public class ReflectiveLoadTimeWeaver implements LoadTimeWeaver { diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleInstrumentableClassLoader.java b/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleInstrumentableClassLoader.java index b2c00f9c3d2..422a083f5c6 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleInstrumentableClassLoader.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleInstrumentableClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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.instrument.classloading; import java.lang.instrument.ClassFileTransformer; import org.springframework.core.OverridingClassLoader; -import org.springframework.lang.UsesJava7; /** * Simplistic implementation of an instrumentable {@code ClassLoader}. @@ -30,13 +29,10 @@ import org.springframework.lang.UsesJava7; * @author Costin Leau * @since 2.0 */ -@UsesJava7 public class SimpleInstrumentableClassLoader extends OverridingClassLoader { static { - if (parallelCapableClassLoaderAvailable) { - ClassLoader.registerAsParallelCapable(); - } + ClassLoader.registerAsParallelCapable(); } diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleThrowawayClassLoader.java b/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleThrowawayClassLoader.java index 011ea17d7c9..88f0bf4d345 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleThrowawayClassLoader.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleThrowawayClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.instrument.classloading; import org.springframework.core.OverridingClassLoader; -import org.springframework.lang.UsesJava7; /** * ClassLoader that can be used to load classes without bringing them @@ -27,13 +26,10 @@ import org.springframework.lang.UsesJava7; * @author Rod Johnson * @since 2.0 */ -@UsesJava7 public class SimpleThrowawayClassLoader extends OverridingClassLoader { static { - if (parallelCapableClassLoaderAvailable) { - ClassLoader.registerAsParallelCapable(); - } + ClassLoader.registerAsParallelCapable(); } diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java index 019952712b8..fe0f7980920 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java @@ -26,8 +26,8 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** - * {@link org.springframework.instrument.classloading.LoadTimeWeaver} implementation for Tomcat's - * new {@link org.apache.tomcat.InstrumentableClassLoader InstrumentableClassLoader}. + * {@link org.springframework.instrument.classloading.LoadTimeWeaver} implementation + * for Tomcat's new {@code org.apache.tomcat.InstrumentableClassLoader}. * Also capable of handling Spring's TomcatInstrumentableClassLoader when encountered. * * @author Juergen Hoeller diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ForkJoinPoolFactoryBean.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ForkJoinPoolFactoryBean.java index 9189b676b9b..bad0fdd27b0 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ForkJoinPoolFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ForkJoinPoolFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,12 +22,9 @@ import java.util.concurrent.TimeUnit; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.UsesJava7; /** * A Spring {@link FactoryBean} that builds and exposes a preconfigured {@link ForkJoinPool}. - * May be used on Java 7 and 8 as well as on Java 6 with {@code jsr166.jar} on the classpath - * (ideally on the VM bootstrap classpath). * *

For details on the ForkJoinPool API and its use with RecursiveActions, see the * JDK 7 javadoc. @@ -38,7 +35,6 @@ import org.springframework.lang.UsesJava7; * @author Juergen Hoeller * @since 3.1 */ -@UsesJava7 public class ForkJoinPoolFactoryBean implements FactoryBean, InitializingBean, DisposableBean { private boolean commonPool = false; diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBean.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBean.java index a9e594580a9..739bdbcb734 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBean.java @@ -24,11 +24,9 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.UsesJava7; import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable; import org.springframework.scheduling.support.TaskUtils; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; /** @@ -75,11 +73,6 @@ import org.springframework.util.ObjectUtils; public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport implements FactoryBean { - // ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 7+ - private static final boolean setRemoveOnCancelPolicyAvailable = - ClassUtils.hasMethod(ScheduledThreadPoolExecutor.class, "setRemoveOnCancelPolicy", boolean.class); - - private int poolSize = 1; private ScheduledExecutorTask[] scheduledExecutorTasks; @@ -150,7 +143,6 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport @Override - @UsesJava7 protected ExecutorService initializeExecutor( ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { @@ -158,7 +150,7 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler); if (this.removeOnCancelPolicy) { - if (setRemoveOnCancelPolicyAvailable && executor instanceof ScheduledThreadPoolExecutor) { + if (executor instanceof ScheduledThreadPoolExecutor) { ((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(true); } else { 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..8d7bf1b0e93 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-2016 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,13 +31,11 @@ import java.util.concurrent.TimeUnit; import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.TaskRejectedException; -import org.springframework.lang.UsesJava7; import org.springframework.scheduling.SchedulingTaskExecutor; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; import org.springframework.scheduling.support.TaskUtils; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.ErrorHandler; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureTask; @@ -58,11 +56,6 @@ import org.springframework.util.concurrent.ListenableFutureTask; public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler { - // ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 7+ - private static final boolean setRemoveOnCancelPolicyAvailable = - ClassUtils.hasMethod(ScheduledThreadPoolExecutor.class, "setRemoveOnCancelPolicy", boolean.class); - - private volatile int poolSize = 1; private volatile boolean removeOnCancelPolicy = false; @@ -91,10 +84,9 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport * switched into remove-on-cancel mode (if possible, with a soft fallback otherwise). *

This setting can be modified at runtime, for example through JMX. */ - @UsesJava7 public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) { this.removeOnCancelPolicy = removeOnCancelPolicy; - if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) { + if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) { ((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy); } else if (removeOnCancelPolicy && this.scheduledExecutor != null) { @@ -110,7 +102,6 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport } - @UsesJava7 @Override protected ExecutorService initializeExecutor( ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { @@ -118,7 +109,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport this.scheduledExecutor = createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler); if (this.removeOnCancelPolicy) { - if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) { + if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) { ((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(true); } else { @@ -187,11 +178,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport * Return the current setting for the remove-on-cancel mode. *

Requires an underlying {@link ScheduledThreadPoolExecutor}. */ - @UsesJava7 public boolean isRemoveOnCancelPolicy() { - if (!setRemoveOnCancelPolicyAvailable) { - return false; - } if (this.scheduledExecutor == null) { // Not initialized yet: return our setting for the time being. return this.removeOnCancelPolicy; diff --git a/spring-context/src/main/java/org/springframework/validation/DataBinder.java b/spring-context/src/main/java/org/springframework/validation/DataBinder.java index 3aceff41baa..880a1bc5c13 100644 --- a/spring-context/src/main/java/org/springframework/validation/DataBinder.java +++ b/spring-context/src/main/java/org/springframework/validation/DataBinder.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -44,9 +43,7 @@ import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.format.Formatter; import org.springframework.format.support.FormatterPropertyEditorAdapter; -import org.springframework.lang.UsesJava8; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.PatternMatchUtils; import org.springframework.util.StringUtils; @@ -124,19 +121,6 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { */ protected static final Log logger = LogFactory.getLog(DataBinder.class); - private static Class javaUtilOptionalClass = null; - - static { - try { - javaUtilOptionalClass = - ClassUtils.forName("java.util.Optional", DataBinder.class.getClassLoader()); - } - catch (ClassNotFoundException ex) { - // Java 8 not available - Optional references simply not supported then. - } - } - - private final Object target; private final String objectName; @@ -183,12 +167,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * @param objectName the name of the target object */ public DataBinder(Object target, String objectName) { - if (target != null && target.getClass() == javaUtilOptionalClass) { - this.target = OptionalUnwrapper.unwrap(target); - } - else { - this.target = target; - } + this.target = ObjectUtils.unwrapOptional(target); this.objectName = objectName; } @@ -884,22 +863,4 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { return getBindingResult().getModel(); } - - /** - * Inner class to avoid a hard dependency on Java 8. - */ - @UsesJava8 - private static class OptionalUnwrapper { - - public static Object unwrap(Object optionalObject) { - Optional optional = (Optional) optionalObject; - if (!optional.isPresent()) { - return null; - } - Object result = optional.get(); - Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported"); - return result; - } - } - } diff --git a/spring-core/src/main/java/org/springframework/core/DecoratingClassLoader.java b/spring-core/src/main/java/org/springframework/core/DecoratingClassLoader.java index b29ac07161d..1b3815fd645 100644 --- a/spring-core/src/main/java/org/springframework/core/DecoratingClassLoader.java +++ b/spring-core/src/main/java/org/springframework/core/DecoratingClassLoader.java @@ -20,9 +20,7 @@ import java.util.Collections; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.springframework.lang.UsesJava7; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; /** * Base class for decorating ClassLoaders such as {@link OverridingClassLoader} @@ -33,20 +31,10 @@ import org.springframework.util.ClassUtils; * @author Rod Johnson * @since 2.5.2 */ -@UsesJava7 public abstract class DecoratingClassLoader extends ClassLoader { - /** - * Java 7+ {@code ClassLoader.registerAsParallelCapable()} available? - * @since 4.1.2 - */ - protected static final boolean parallelCapableClassLoaderAvailable = - ClassUtils.hasMethod(ClassLoader.class, "registerAsParallelCapable"); - static { - if (parallelCapableClassLoaderAvailable) { - ClassLoader.registerAsParallelCapable(); - } + ClassLoader.registerAsParallelCapable(); } diff --git a/spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java index 72c07672344..fcd640714d2 100644 --- a/spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/DefaultParameterNameDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package org.springframework.core; -import org.springframework.util.ClassUtils; - /** * Default implementation of the {@link ParameterNameDiscoverer} strategy interface, * using the Java 8 standard reflection mechanism (if available), and falling back @@ -33,14 +31,8 @@ import org.springframework.util.ClassUtils; */ public class DefaultParameterNameDiscoverer extends PrioritizedParameterNameDiscoverer { - private static final boolean standardReflectionAvailable = ClassUtils.isPresent( - "java.lang.reflect.Executable", DefaultParameterNameDiscoverer.class.getClassLoader()); - - public DefaultParameterNameDiscoverer() { - if (standardReflectionAvailable) { - addDiscoverer(new StandardReflectionParameterNameDiscoverer()); - } + addDiscoverer(new StandardReflectionParameterNameDiscoverer()); addDiscoverer(new LocalVariableTableParameterNameDiscoverer()); } diff --git a/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java b/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java index 5a2b2df765d..edf92355de9 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java +++ b/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java @@ -85,10 +85,9 @@ public abstract class MethodIntrospector { /** * Select methods on the given target type based on a filter. - *

Callers define methods of interest through the - * {@link ReflectionUtils.MethodFilter} parameter. + *

Callers define methods of interest through the {@code MethodFilter} parameter. * @param targetType the target type to search methods on - * @param methodFilter a {@link ReflectionUtils.MethodFilter} to help + * @param methodFilter a {@code MethodFilter} to help * recognize handler methods of interest * @return the selected methods, or an empty set in case of no match */ diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 48344a91ad9..86179de64d3 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -25,9 +25,9 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; /** * Helper class that encapsulates the specification of a method parameter, i.e. a {@link Method} @@ -48,21 +48,6 @@ import org.springframework.util.ClassUtils; */ public class MethodParameter { - private static final Class javaUtilOptionalClass; - - static { - Class clazz; - try { - clazz = ClassUtils.forName("java.util.Optional", MethodParameter.class.getClassLoader()); - } - catch (ClassNotFoundException ex) { - // Java 8 not available - Optional references simply not supported then. - clazz = null; - } - javaUtilOptionalClass = clazz; - } - - private final Method method; private final Constructor constructor; @@ -320,7 +305,7 @@ public class MethodParameter { * @since 4.3 */ public boolean isOptional() { - return (getParameterType() == javaUtilOptionalClass); + return (getParameterType() == Optional.class); } /** diff --git a/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java b/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java index c0bc9f32f59..5a45cde1f2e 100644 --- a/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java +++ b/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java @@ -19,7 +19,6 @@ package org.springframework.core; import java.io.IOException; import java.io.InputStream; -import org.springframework.lang.UsesJava7; import org.springframework.util.FileCopyUtils; /** @@ -34,7 +33,6 @@ import org.springframework.util.FileCopyUtils; * @author Juergen Hoeller * @since 2.0.1 */ -@UsesJava7 public class OverridingClassLoader extends DecoratingClassLoader { /** Packages that are excluded by default */ @@ -44,9 +42,7 @@ public class OverridingClassLoader extends DecoratingClassLoader { private static final String CLASS_FILE_SUFFIX = ".class"; static { - if (parallelCapableClassLoaderAvailable) { - ClassLoader.registerAsParallelCapable(); - } + ClassLoader.registerAsParallelCapable(); } diff --git a/spring-core/src/main/java/org/springframework/core/StandardReflectionParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/StandardReflectionParameterNameDiscoverer.java index 6ce5f08166e..f263681aed4 100644 --- a/spring-core/src/main/java/org/springframework/core/StandardReflectionParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/StandardReflectionParameterNameDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,8 +20,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Parameter; -import org.springframework.lang.UsesJava8; - /** * {@link ParameterNameDiscoverer} implementation which uses JDK 8's reflection facilities * for introspecting parameter names (based on the "-parameters" compiler flag). @@ -30,7 +28,6 @@ import org.springframework.lang.UsesJava8; * @since 4.0 * @see java.lang.reflect.Parameter#getName() */ -@UsesJava8 public class StandardReflectionParameterNameDiscoverer implements ParameterNameDiscoverer { @Override diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index dd5f180180d..85a15f66c79 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -28,7 +28,6 @@ import java.util.stream.Stream; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.UsesJava8; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -49,9 +48,6 @@ public class TypeDescriptor implements Serializable { static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0]; - private static final boolean streamAvailable = ClassUtils.isPresent( - "java.util.stream.Stream", TypeDescriptor.class.getClassLoader()); - private static final Map, TypeDescriptor> commonTypesCache = new HashMap, TypeDescriptor>(18); private static final Class[] CACHED_COMMON_TYPES = { @@ -340,10 +336,10 @@ public class TypeDescriptor implements Serializable { if (this.resolvableType.isArray()) { return new TypeDescriptor(this.resolvableType.getComponentType(), null, this.annotations); } - if (streamAvailable && StreamDelegate.isStream(this.type)) { - return StreamDelegate.getStreamElementType(this); + if (Stream.class.isAssignableFrom(this.type)) { + return getRelatedIfResolvable(this, this.resolvableType.as(Stream.class).getGeneric(0)); } - return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric()); + return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric(0)); } /** @@ -694,20 +690,4 @@ public class TypeDescriptor implements Serializable { return new TypeDescriptor(type, null, source.annotations); } - - /** - * Inner class to avoid a hard dependency on Java 8. - */ - @UsesJava8 - private static class StreamDelegate { - - public static boolean isStream(Class type) { - return Stream.class.isAssignableFrom(type); - } - - public static TypeDescriptor getStreamElementType(TypeDescriptor source) { - return getRelatedIfResolvable(source, source.resolvableType.as(Stream.class).getGeneric()); - } - } - } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java index 86df6337f63..697f3b4f217 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java @@ -40,19 +40,10 @@ import org.springframework.util.ClassUtils; */ public class DefaultConversionService extends GenericConversionService { - /** Java 8's java.util.Optional class available? */ - private static final boolean javaUtilOptionalClassAvailable = - ClassUtils.isPresent("java.util.Optional", DefaultConversionService.class.getClassLoader()); - /** Java 8's java.time package available? */ private static final boolean jsr310Available = ClassUtils.isPresent("java.time.ZoneId", DefaultConversionService.class.getClassLoader()); - /** Java 8's java.util.stream.Stream class available? */ - private static final boolean streamAvailable = ClassUtils.isPresent( - "java.util.stream.Stream", DefaultConversionService.class.getClassLoader()); - - /** * Create a new {@code DefaultConversionService} with the set of @@ -83,9 +74,7 @@ public class DefaultConversionService extends GenericConversionService { converterRegistry.addConverter(new ObjectToObjectConverter()); converterRegistry.addConverter(new IdToEntityConverter((ConversionService) converterRegistry)); converterRegistry.addConverter(new FallbackObjectToStringConverter()); - if (javaUtilOptionalClassAvailable) { - converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry)); - } + converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry)); } /** @@ -117,9 +106,7 @@ public class DefaultConversionService extends GenericConversionService { converterRegistry.addConverter(new CollectionToObjectConverter(conversionService)); converterRegistry.addConverter(new ObjectToCollectionConverter(conversionService)); - if (streamAvailable) { - converterRegistry.addConverter(new StreamConverter(conversionService)); - } + converterRegistry.addConverter(new StreamConverter(conversionService)); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index e051e6cc494..1790b617903 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -25,6 +25,7 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.springframework.core.ResolvableType; @@ -72,20 +73,6 @@ public class GenericConversionService implements ConfigurableConversionService { private static final GenericConverter NO_MATCH = new NoOpConverter("NO_MATCH"); - /** Java 8's java.util.Optional.empty() */ - private static Object javaUtilOptionalEmpty = null; - - static { - try { - Class clazz = ClassUtils.forName("java.util.Optional", GenericConversionService.class.getClassLoader()); - javaUtilOptionalEmpty = ClassUtils.getMethod(clazz, "empty").invoke(null); - } - catch (Exception ex) { - // Java 8 not available - conversion to Optional not supported then. - } - } - - private final Converters converters = new Converters(); private final Map converterCache = @@ -231,8 +218,8 @@ public class GenericConversionService implements ConfigurableConversionService { * @return the converted null object */ protected Object convertNullSource(TypeDescriptor sourceType, TypeDescriptor targetType) { - if (javaUtilOptionalEmpty != null && targetType.getObjectType() == javaUtilOptionalEmpty.getClass()) { - return javaUtilOptionalEmpty; + if (targetType.getObjectType() == Optional.class) { + return Optional.empty(); } return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java index 8c701201109..099cc66cf2d 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ import java.util.Set; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.UsesJava8; /** * Convert an Object to {@code java.util.Optional} if necessary using the @@ -34,7 +33,6 @@ import org.springframework.lang.UsesJava8; * @author Juergen Hoeller * @since 4.1 */ -@UsesJava8 final class ObjectToOptionalConverter implements ConditionalGenericConverter { private final ConversionService conversionService; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java index 94930eaa70e..3ef3bbffabc 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import java.util.stream.Stream; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.UsesJava8; /** * Converts a {@link Stream} to and from a collection or array, converting the @@ -35,7 +34,6 @@ import org.springframework.lang.UsesJava8; * @author Stephane Nicoll * @since 4.2 */ -@UsesJava8 class StreamConverter implements ConditionalGenericConverter { private static final TypeDescriptor STREAM_TYPE = TypeDescriptor.valueOf(Stream.class); diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToTimeZoneConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToTimeZoneConverter.java index cf8565d33cf..e0559f3a50e 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToTimeZoneConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToTimeZoneConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.core.convert.support; import java.util.TimeZone; import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.UsesJava8; import org.springframework.util.StringUtils; /** @@ -28,7 +27,6 @@ import org.springframework.util.StringUtils; * @author Stephane Nicoll * @since 4.2 */ -@UsesJava8 class StringToTimeZoneConverter implements Converter { @Override diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ZoneIdToTimeZoneConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ZoneIdToTimeZoneConverter.java index e91a738c649..87020c34a35 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ZoneIdToTimeZoneConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ZoneIdToTimeZoneConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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.time.ZoneId; import java.util.TimeZone; import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.UsesJava8; /** * Simple converter from Java 8's {@link java.time.ZoneId} to {@link java.util.TimeZone}. @@ -35,7 +34,6 @@ import org.springframework.lang.UsesJava8; * @since 4.0 * @see TimeZone#getTimeZone(java.time.ZoneId) */ -@UsesJava8 final class ZoneIdToTimeZoneConverter implements Converter { @Override diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ZonedDateTimeToCalendarConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ZonedDateTimeToCalendarConverter.java index 7fd16ee0b21..1bfbccd68a5 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ZonedDateTimeToCalendarConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ZonedDateTimeToCalendarConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,7 +21,6 @@ import java.util.Calendar; import java.util.GregorianCalendar; import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.UsesJava8; /** * Simple converter from Java 8's {@link java.time.ZonedDateTime} to {@link java.util.Calendar}. @@ -36,7 +35,6 @@ import org.springframework.lang.UsesJava8; * @since 4.0.1 * @see java.util.GregorianCalendar#from(java.time.ZonedDateTime) */ -@UsesJava8 final class ZonedDateTimeToCalendarConverter implements Converter { @Override diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index f84ccfa9083..649cf5f7c47 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,6 @@ import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.Paths; -import org.springframework.lang.UsesJava7; import org.springframework.util.Assert; /** @@ -41,7 +40,6 @@ import org.springframework.util.Assert; * @since 4.0 * @see java.nio.file.Path */ -@UsesJava7 public class PathResource extends AbstractResource implements WritableResource { private final Path path; diff --git a/spring-core/src/main/java/org/springframework/lang/UsesJava7.java b/spring-core/src/main/java/org/springframework/lang/UsesJava7.java index d88b27bdf27..aab6906366e 100644 --- a/spring-core/src/main/java/org/springframework/lang/UsesJava7.java +++ b/spring-core/src/main/java/org/springframework/lang/UsesJava7.java @@ -32,5 +32,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.CLASS) @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) @Documented +@Deprecated public @interface UsesJava7 { } diff --git a/spring-core/src/main/java/org/springframework/lang/UsesJava8.java b/spring-core/src/main/java/org/springframework/lang/UsesJava8.java index af6a84bdea4..11e02dd6e71 100644 --- a/spring-core/src/main/java/org/springframework/lang/UsesJava8.java +++ b/spring-core/src/main/java/org/springframework/lang/UsesJava8.java @@ -32,5 +32,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.CLASS) @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) @Documented +@Deprecated public @interface UsesJava8 { } diff --git a/spring-core/src/main/java/org/springframework/util/Base64Utils.java b/spring-core/src/main/java/org/springframework/util/Base64Utils.java index 17c48614b83..7742a990862 100644 --- a/spring-core/src/main/java/org/springframework/util/Base64Utils.java +++ b/spring-core/src/main/java/org/springframework/util/Base64Utils.java @@ -18,62 +18,22 @@ package org.springframework.util; import java.nio.charset.Charset; import java.util.Base64; -import javax.xml.bind.DatatypeConverter; - -import org.springframework.lang.UsesJava8; /** * A simple utility class for Base64 encoding and decoding. * - *

Adapts to either Java 8's {@link java.util.Base64} class or Apache Commons Codec's - * {@link org.apache.commons.codec.binary.Base64} class. With neither Java 8 nor Commons - * Codec present, {@link #encode}/{@link #decode} calls will throw an IllegalStateException. - * However, as of Spring 4.2, {@link #encodeToString} and {@link #decodeFromString} will - * nevertheless work since they can delegate to the JAXB DatatypeConverter as a fallback. - * However, this does not apply when using the ...UrlSafe... methods for RFC 4648 "URL and - * Filename Safe Alphabet"; a delegate is required. - *

- * Note: Apache Commons Codec does not add padding ({@code =}) when encoding with - * the URL and Filename Safe Alphabet. + *

Adapts to Java 8's {@link java.util.Base64} in a convenience fashion. * * @author Juergen Hoeller * @author Gary Russell * @since 4.1 * @see java.util.Base64 - * @see org.apache.commons.codec.binary.Base64 - * @see javax.xml.bind.DatatypeConverter#printBase64Binary - * @see javax.xml.bind.DatatypeConverter#parseBase64Binary */ public abstract class Base64Utils { private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - private static final Base64Delegate delegate; - - static { - Base64Delegate delegateToUse = null; - // JDK 8's java.util.Base64 class present? - if (ClassUtils.isPresent("java.util.Base64", Base64Utils.class.getClassLoader())) { - delegateToUse = new JdkBase64Delegate(); - } - // Apache Commons Codec present on the classpath? - else if (ClassUtils.isPresent("org.apache.commons.codec.binary.Base64", Base64Utils.class.getClassLoader())) { - delegateToUse = new CommonsCodecBase64Delegate(); - } - delegate = delegateToUse; - } - - /** - * Assert that Byte64 encoding between byte arrays is actually supported. - * @throws IllegalStateException if neither Java 8 nor Apache Commons Codec is present - */ - private static void assertDelegateAvailable() { - Assert.state(delegate != null, - "Neither Java 8 nor Apache Commons Codec found - Base64 encoding between byte arrays not supported"); - } - - /** * Base64-encode the given byte array. * @param src the original byte array (may be {@code null}) @@ -82,8 +42,10 @@ public abstract class Base64Utils { * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime */ public static byte[] encode(byte[] src) { - assertDelegateAvailable(); - return delegate.encode(src); + if (src == null || src.length == 0) { + return src; + } + return Base64.getEncoder().encode(src); } /** @@ -94,8 +56,10 @@ public abstract class Base64Utils { * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime */ public static byte[] decode(byte[] src) { - assertDelegateAvailable(); - return delegate.decode(src); + if (src == null || src.length == 0) { + return src; + } + return Base64.getDecoder().decode(src); } /** @@ -108,8 +72,10 @@ public abstract class Base64Utils { * @since 4.2.4 */ public static byte[] encodeUrlSafe(byte[] src) { - assertDelegateAvailable(); - return delegate.encodeUrlSafe(src); + if (src == null || src.length == 0) { + return src; + } + return Base64.getUrlEncoder().encode(src); } /** @@ -122,8 +88,10 @@ public abstract class Base64Utils { * @since 4.2.4 */ public static byte[] decodeUrlSafe(byte[] src) { - assertDelegateAvailable(); - return delegate.decodeUrlSafe(src); + if (src == null || src.length == 0) { + return src; + } + return Base64.getUrlDecoder().decode(src); } /** @@ -139,15 +107,7 @@ public abstract class Base64Utils { if (src.length == 0) { return ""; } - - if (delegate != null) { - // Full encoder available - return new String(delegate.encode(src), DEFAULT_CHARSET); - } - else { - // JAXB fallback for String case - return DatatypeConverter.printBase64Binary(src); - } + return new String(encode(src), DEFAULT_CHARSET); } /** @@ -162,15 +122,7 @@ public abstract class Base64Utils { if (src.length() == 0) { return new byte[0]; } - - if (delegate != null) { - // Full encoder available - return delegate.decode(src.getBytes(DEFAULT_CHARSET)); - } - else { - // JAXB fallback for String case - return DatatypeConverter.parseBase64Binary(src); - } + return decode(src.getBytes(DEFAULT_CHARSET)); } /** @@ -183,8 +135,7 @@ public abstract class Base64Utils { * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime */ public static String encodeToUrlSafeString(byte[] src) { - assertDelegateAvailable(); - return new String(delegate.encodeUrlSafe(src), DEFAULT_CHARSET); + return new String(encodeUrlSafe(src), DEFAULT_CHARSET); } /** @@ -196,89 +147,7 @@ public abstract class Base64Utils { * supported, i.e. neither Java 8 nor Apache Commons Codec is present at runtime */ public static byte[] decodeFromUrlSafeString(String src) { - assertDelegateAvailable(); - return delegate.decodeUrlSafe(src.getBytes(DEFAULT_CHARSET)); - } - - - interface Base64Delegate { - - byte[] encode(byte[] src); - - byte[] decode(byte[] src); - - byte[] encodeUrlSafe(byte[] src); - - byte[] decodeUrlSafe(byte[] src); - } - - - @UsesJava8 - static class JdkBase64Delegate implements Base64Delegate { - - @Override - public byte[] encode(byte[] src) { - if (src == null || src.length == 0) { - return src; - } - return Base64.getEncoder().encode(src); - } - - @Override - public byte[] decode(byte[] src) { - if (src == null || src.length == 0) { - return src; - } - return Base64.getDecoder().decode(src); - } - - @Override - public byte[] encodeUrlSafe(byte[] src) { - if (src == null || src.length == 0) { - return src; - } - return Base64.getUrlEncoder().encode(src); - } - - @Override - public byte[] decodeUrlSafe(byte[] src) { - if (src == null || src.length == 0) { - return src; - } - return Base64.getUrlDecoder().decode(src); - } - - } - - - static class CommonsCodecBase64Delegate implements Base64Delegate { - - private final org.apache.commons.codec.binary.Base64 base64 = - new org.apache.commons.codec.binary.Base64(); - - private final org.apache.commons.codec.binary.Base64 base64UrlSafe = - new org.apache.commons.codec.binary.Base64(0, null, true); - - @Override - public byte[] encode(byte[] src) { - return this.base64.encode(src); - } - - @Override - public byte[] decode(byte[] src) { - return this.base64.decode(src); - } - - @Override - public byte[] encodeUrlSafe(byte[] src) { - return this.base64UrlSafe.encode(src); - } - - @Override - public byte[] decodeUrlSafe(byte[] src) { - return this.base64UrlSafe.decode(src); - } - + return decodeUrlSafe(src.getBytes(DEFAULT_CHARSET)); } } diff --git a/spring-core/src/main/java/org/springframework/util/DigestUtils.java b/spring-core/src/main/java/org/springframework/util/DigestUtils.java index 8de0b513cdc..6251c7aa968 100644 --- a/spring-core/src/main/java/org/springframework/util/DigestUtils.java +++ b/spring-core/src/main/java/org/springframework/util/DigestUtils.java @@ -24,13 +24,12 @@ import java.security.NoSuchAlgorithmException; /** * Miscellaneous methods for calculating digests. *

Mainly for internal use within the framework; consider - * Apache Commons Codec for a - * more comprehensive suite of digest utilities. + * Apache Commons Codec + * for a more comprehensive suite of digest utilities. * * @author Arjen Poutsma * @author Craig Andrews * @since 3.0 - * @see org.apache.commons.codec.digest.DigestUtils */ public abstract class DigestUtils { diff --git a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java index 624d6d35678..801f167f976 100644 --- a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java @@ -20,6 +20,7 @@ import java.lang.reflect.Array; import java.util.Arrays; import java.util.Collection; import java.util.Map; +import java.util.Optional; /** * Miscellaneous object utility methods. @@ -109,6 +110,7 @@ public abstract class ObjectUtils { * Determine whether the given object is empty. *

This method supports the following object types. *

    + *
  • {@code Optional}: considered empty if {@link Optional#empty()}
  • *
  • {@code Array}: considered empty if its length is zero
  • *
  • {@link CharSequence}: considered empty if its length is zero
  • *
  • {@link Collection}: delegates to {@link Collection#isEmpty()}
  • @@ -119,6 +121,7 @@ public abstract class ObjectUtils { * @param obj the object to check * @return {@code true} if the object is {@code null} or empty * @since 4.2 + * @see Optional#isPresent() * @see ObjectUtils#isEmpty(Object[]) * @see StringUtils#hasLength(CharSequence) * @see StringUtils#isEmpty(Object) @@ -131,6 +134,9 @@ public abstract class ObjectUtils { return true; } + if (obj instanceof Optional) { + return !((Optional) obj).isPresent(); + } if (obj.getClass().isArray()) { return Array.getLength(obj) == 0; } @@ -148,6 +154,26 @@ public abstract class ObjectUtils { return false; } + /** + * Unwrap the given object which is potentially a {@link java.util.Optional}. + * @param obj the candidate object + * @return either the value held within the {@code Optional}, {@code null} + * if the {@code Optional} is empty, or simply the given object as-is + * @since 5.0 + */ + public static Object unwrapOptional(Object obj) { + if (obj instanceof Optional) { + Optional optional = (Optional) obj; + if (!optional.isPresent()) { + return null; + } + Object result = optional.get(); + Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported"); + return result; + } + return obj; + } + /** * Check whether the given array contains the given element. * @param array the array to check (may be {@code null}, diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java b/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java index f42a88f4af4..18707cf43b8 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,22 +22,19 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.BiFunction; -import org.springframework.lang.UsesJava8; - - /** * Adapts a {@link CompletableFuture} into a {@link ListenableFuture}. * * @author Sebastien Deleuze * @since 4.2 */ -@UsesJava8 public class CompletableToListenableFutureAdapter implements ListenableFuture { private final CompletableFuture completableFuture; private final ListenableFutureCallbackRegistry callbacks = new ListenableFutureCallbackRegistry(); + public CompletableToListenableFutureAdapter(CompletableFuture completableFuture) { this.completableFuture = completableFuture; this.completableFuture.handle(new BiFunction() { @@ -54,6 +51,7 @@ public class CompletableToListenableFutureAdapter implements ListenableFuture }); } + @Override public void addCallback(ListenableFutureCallback callback) { this.callbacks.addCallback(callback); diff --git a/spring-core/src/test/java/org/springframework/util/Base64UtilsTests.java b/spring-core/src/test/java/org/springframework/util/Base64UtilsTests.java index bbbb003b1bb..cd12f7e4b16 100644 --- a/spring-core/src/test/java/org/springframework/util/Base64UtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/Base64UtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.util; import java.io.UnsupportedEncodingException; - import javax.xml.bind.DatatypeConverter; import org.junit.Test; @@ -31,41 +30,26 @@ import static org.junit.Assert.*; public class Base64UtilsTests { @Test - public void encodeWithJdk8VsCommonsCodec() throws UnsupportedEncodingException { - Base64Utils.Base64Delegate jdkDelegate = new Base64Utils.JdkBase64Delegate(); - Base64Utils.Base64Delegate commonsDelegate = new Base64Utils.CommonsCodecBase64Delegate(); - + public void encode() throws UnsupportedEncodingException { byte[] bytes = new byte[] {-0x4f, 0xa, -0x73, -0x4f, 0x64, -0x20, 0x75, 0x41, 0x5, -0x49, -0x57, -0x65, -0x19, 0x2e, 0x3f, -0x1b}; - assertArrayEquals(jdkDelegate.encode(bytes), commonsDelegate.encode(bytes)); - assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes))); - assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes))); + assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes))); bytes = "Hello World".getBytes("UTF-8"); - assertArrayEquals(jdkDelegate.encode(bytes), commonsDelegate.encode(bytes)); - assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes))); - assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes))); + assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes))); bytes = "Hello World\r\nSecond Line".getBytes("UTF-8"); - assertArrayEquals(jdkDelegate.encode(bytes), commonsDelegate.encode(bytes)); - assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes))); - assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes))); + assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes))); bytes = "Hello World\r\nSecond Line\r\n".getBytes("UTF-8"); - assertArrayEquals(jdkDelegate.encode(bytes), commonsDelegate.encode(bytes)); - assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes))); - assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes))); + assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes))); bytes = new byte[] { (byte) 0xfb, (byte) 0xf0 }; - assertArrayEquals("+/A=".getBytes(), jdkDelegate.encode(bytes)); - assertArrayEquals("+/A=".getBytes(), commonsDelegate.encode(bytes)); - assertArrayEquals(bytes, jdkDelegate.decode(jdkDelegate.encode(bytes))); - assertArrayEquals(bytes, commonsDelegate.decode(commonsDelegate.encode(bytes))); + assertArrayEquals("+/A=".getBytes(), Base64Utils.encode(bytes)); + assertArrayEquals(bytes, Base64Utils.decode(Base64Utils.encode(bytes))); - assertArrayEquals("-_A=".getBytes(), jdkDelegate.encodeUrlSafe(bytes)); - assertArrayEquals("-_A".getBytes(), commonsDelegate.encodeUrlSafe(bytes)); // no padding with commons and URL safe - assertArrayEquals(bytes, jdkDelegate.decodeUrlSafe(jdkDelegate.encodeUrlSafe(bytes))); - assertArrayEquals(bytes, commonsDelegate.decodeUrlSafe(commonsDelegate.encodeUrlSafe(bytes))); + assertArrayEquals("-_A=".getBytes(), Base64Utils.encodeUrlSafe(bytes)); + assertArrayEquals(bytes, Base64Utils.decodeUrlSafe(Base64Utils.encodeUrlSafe(bytes))); } @Test diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java index 355009656d7..b5b6ec2971b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlRowSetResultSetExtractor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,17 +24,12 @@ import javax.sql.rowset.RowSetProvider; import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet; import org.springframework.jdbc.support.rowset.SqlRowSet; -import org.springframework.lang.UsesJava7; -import org.springframework.util.ClassUtils; /** * {@link ResultSetExtractor} implementation that returns a Spring {@link SqlRowSet} * representation for each given {@link ResultSet}. * *

    The default implementation uses a standard JDBC CachedRowSet underneath. - * This means that JDBC RowSet support needs to be available at runtime: - * by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} class on Java 6, - * or the {@code javax.sql.rowset.RowSetProvider} mechanism on Java 7+ / JDBC 4.1+. * * @author Juergen Hoeller * @since 1.2 @@ -45,17 +40,14 @@ import org.springframework.util.ClassUtils; */ public class SqlRowSetResultSetExtractor implements ResultSetExtractor { - private static final CachedRowSetFactory cachedRowSetFactory; + private static final RowSetFactory rowSetFactory; static { - if (ClassUtils.isPresent("javax.sql.rowset.RowSetProvider", - SqlRowSetResultSetExtractor.class.getClassLoader())) { - // using JDBC 4.1 RowSetProvider, available on JDK 7+ - cachedRowSetFactory = new StandardCachedRowSetFactory(); + try { + rowSetFactory = RowSetProvider.newFactory(); } - else { - // JDBC 4.1 API not available - fall back to Sun CachedRowSetImpl on JDK 6 - cachedRowSetFactory = new SunCachedRowSetFactory(); + catch (SQLException ex) { + throw new IllegalStateException("Cannot create RowSetFactory through RowSetProvider", ex); } } @@ -94,69 +86,7 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor implementationClass; - - static { - try { - implementationClass = ClassUtils.forName("com.sun.rowset.CachedRowSetImpl", - SqlRowSetResultSetExtractor.class.getClassLoader()); - } - catch (Throwable ex) { - throw new IllegalStateException(ex); - } - } - - @Override - public CachedRowSet createCachedRowSet() throws SQLException { - try { - return (CachedRowSet) implementationClass.newInstance(); - } - catch (Throwable ex) { - throw new IllegalStateException(ex); - } - } + return rowSetFactory.createCachedRowSet(); } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java index 176364d18a1..dc64a2cae13 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,8 +36,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.datasource.DataSourceUtils; -import org.springframework.lang.UsesJava7; -import org.springframework.util.ClassUtils; /** * Generic utility methods for working with JDBC. Mainly for internal use @@ -54,11 +52,6 @@ public abstract class JdbcUtils { */ public static final int TYPE_UNKNOWN = Integer.MIN_VALUE; - - // Check for JDBC 4.1 getObject(int, Class) method - available on JDK 7 and higher - private static final boolean getObjectWithTypeAvailable = - ClassUtils.hasMethod(ResultSet.class, "getObject", int.class, Class.class); - private static final Log logger = LogFactory.getLog(JdbcUtils.class); @@ -135,7 +128,6 @@ public abstract class JdbcUtils { * @return the value object * @throws SQLException if thrown by the JDBC API */ - @UsesJava7 // guard optional use of JDBC 4.1 (safe with 1.6 due to getObjectWithTypeAvailable check) public static Object getResultSetValue(ResultSet rs, int index, Class requiredType) throws SQLException { if (requiredType == null) { return getResultSetValue(rs, index); @@ -192,19 +184,17 @@ public abstract class JdbcUtils { } else { // Some unknown type desired -> rely on getObject. - if (getObjectWithTypeAvailable) { - try { - return rs.getObject(index, requiredType); - } - catch (AbstractMethodError err) { - logger.debug("JDBC driver does not implement JDBC 4.1 'getObject(int, Class)' method", err); - } - catch (SQLFeatureNotSupportedException ex) { - logger.debug("JDBC driver does not support JDBC 4.1 'getObject(int, Class)' method", ex); - } - catch (SQLException ex) { - logger.debug("JDBC driver has limited support for JDBC 4.1 'getObject(int, Class)' method", ex); - } + try { + return rs.getObject(index, requiredType); + } + catch (AbstractMethodError err) { + logger.debug("JDBC driver does not implement JDBC 4.1 'getObject(int, Class)' method", err); + } + catch (SQLFeatureNotSupportedException ex) { + logger.debug("JDBC driver does not support JDBC 4.1 'getObject(int, Class)' method", ex); + } + catch (SQLException ex) { + logger.debug("JDBC driver has limited support for JDBC 4.1 'getObject(int, Class)' method", ex); } // Fall back to getObject without type specification... return getResultSetValue(rs, index); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java index 98232269f80..0f07b94b302 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,6 @@ import java.util.HashMap; import java.util.Map; import org.springframework.jdbc.InvalidResultSetAccessException; -import org.springframework.lang.UsesJava7; /** * The default implementation of Spring's {@link SqlRowSet} interface, wrapping a @@ -412,7 +411,6 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { /** * @see java.sql.ResultSet#getObject(int, Class) */ - @UsesJava7 @Override public T getObject(int columnIndex, Class type) throws InvalidResultSetAccessException { try { 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 12d9d8d8bb9..965af158804 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 @@ -40,7 +40,7 @@ import org.springframework.util.MimeType; * {@link Marshaller} and {@link Unmarshaller} abstractions. * *

    This converter requires a {@code Marshaller} and {@code Unmarshaller} before it can - * be used. These can be injected by the {@linkplain MarshallingMessageConverter(Marshaller) + * be used. These can be injected by the {@linkplain #MarshallingMessageConverter(Marshaller) * constructor} or {@linkplain #setMarshaller(Marshaller) bean properties}. * * @author Arjen Poutsma diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethodSelector.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethodSelector.java deleted file mode 100644 index 69bd0c1aca1..00000000000 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethodSelector.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2002-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.messaging.handler; - -import java.lang.reflect.Method; -import java.util.Set; - -import org.springframework.core.MethodIntrospector; -import org.springframework.util.ReflectionUtils.MethodFilter; - -/** - * Defines the algorithm for searching handler methods exhaustively including interfaces and parent - * classes while also dealing with parameterized methods as well as interface and class-based proxies. - * - * @author Rossen Stoyanchev - * @since 4.0 - * @deprecated as of Spring 4.2.3, in favor of the generalized and refined {@link MethodIntrospector} - */ -@Deprecated -public abstract class HandlerMethodSelector { - - /** - * Select handler methods for the given handler type. - *

    Callers define handler methods of interest through the {@link MethodFilter} parameter. - * @param handlerType the handler type to search handler methods on - * @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest - * @return the selected methods, or an empty set - * @see MethodIntrospector#selectMethods(Class, MethodFilter) - */ - public static Set selectMethods(Class handlerType, MethodFilter handlerMethodFilter) { - return MethodIntrospector.selectMethods(handlerType, handlerMethodFilter); - } - -} diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/CompletableFutureReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/CompletableFutureReturnValueHandler.java index 83b6afd704b..6a0454dee2c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/CompletableFutureReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/CompletableFutureReturnValueHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.messaging.handler.invocation; import java.util.concurrent.CompletableFuture; import org.springframework.core.MethodParameter; -import org.springframework.lang.UsesJava8; import org.springframework.util.concurrent.CompletableToListenableFutureAdapter; import org.springframework.util.concurrent.ListenableFuture; @@ -29,7 +28,6 @@ import org.springframework.util.concurrent.ListenableFuture; * @author Sebastien Deleuze * @since 4.2 */ -@UsesJava8 public class CompletableFutureReturnValueHandler extends AbstractAsyncReturnValueHandler { @Override diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java index 8116540280f..0817a7362d9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java @@ -67,7 +67,6 @@ import org.springframework.messaging.support.MessageHeaderInitializer; import org.springframework.stereotype.Controller; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.PathMatcher; import org.springframework.util.StringValueResolver; @@ -87,10 +86,6 @@ import org.springframework.validation.Validator; public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler implements EmbeddedValueResolverAware, SmartLifecycle { - private static final boolean completableFuturePresent = ClassUtils.isPresent( - "java.util.concurrent.CompletableFuture", SimpAnnotationMethodMessageHandler.class.getClassLoader()); - - private final SubscribableChannel clientInboundChannel; private final SimpMessageSendingOperations clientMessagingTemplate; @@ -331,9 +326,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan // Single-purpose return value types handlers.add(new ListenableFutureReturnValueHandler()); - if (completableFuturePresent) { - handlers.add(new CompletableFutureReturnValueHandler()); - } + handlers.add(new CompletableFutureReturnValueHandler()); // Annotation-based return value types SendToMethodReturnValueHandler sendToHandler = diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java index 2d27db7d2b7..84d29f92961 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java @@ -86,7 +86,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC private static final String MVC_VALIDATOR_NAME = "mvcValidator"; - private static final boolean jackson2Present= ClassUtils.isPresent( + private static final boolean jackson2Present = ClassUtils.isPresent( "com.fasterxml.jackson.databind.ObjectMapper", AbstractMessageBrokerConfiguration.class.getClassLoader()); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java index 8cfd8e99d28..c64eb2e505d 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -279,7 +279,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage * InstrumentationLoadTimeWeaver, which requires a Spring-specific (but very general) * VM agent specified on JVM startup, and ReflectiveLoadTimeWeaver, which interacts * with an underlying ClassLoader based on specific extended methods being available - * on it (for example, interacting with Spring's TomcatInstrumentableClassLoader). + * on it. *

    NOTE: As of Spring 2.5, the context's default LoadTimeWeaver (defined * as bean with name "loadTimeWeaver") will be picked up automatically, if available, * removing the need for LoadTimeWeaver configuration on each affected target bean. @@ -290,7 +290,6 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage * is responsible for the weaving configuration. * @see org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver * @see org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver - * @see org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader */ @Override public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java index df4608637d1..8428f094715 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java @@ -176,6 +176,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect { return new SessionTransactionData(session, previousFlushMode, null, null); } + @SuppressWarnings("deprecation") protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException { FlushMode flushMode = (FlushMode) ReflectionUtils.invokeMethod(getFlushMode, session); if (readOnly) { @@ -330,6 +331,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect { this.previousIsolationLevel = previousIsolationLevel; } + @SuppressWarnings("deprecation") public void resetSessionState() { if (this.previousFlushMode != null) { this.session.setFlushMode(this.previousFlushMode); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java index a11a13d878a..54bd8b9dade 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaVendorAdapter.java @@ -24,16 +24,12 @@ import javax.persistence.spi.PersistenceProvider; import org.hibernate.cfg.Environment; import org.hibernate.dialect.DB2Dialect; -import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.InformixDialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.Oracle9iDialect; -import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.dialect.SQLServerDialect; -import org.hibernate.jpa.HibernateEntityManager; -import org.hibernate.jpa.HibernateEntityManagerFactory; /** * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Hibernate @@ -64,12 +60,11 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { private final Class entityManagerInterface; - @SuppressWarnings("unchecked") + @SuppressWarnings("deprecation") public HibernateJpaVendorAdapter() { - ClassLoader cl = HibernateJpaVendorAdapter.class.getClassLoader(); this.persistenceProvider = new SpringHibernateJpaPersistenceProvider(); - this.entityManagerFactoryInterface = HibernateEntityManagerFactory.class; - this.entityManagerInterface = HibernateEntityManager.class; + this.entityManagerFactoryInterface = org.hibernate.jpa.HibernateEntityManagerFactory.class; + this.entityManagerInterface = org.hibernate.jpa.HibernateEntityManager.class; } @@ -142,13 +137,13 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { protected Class determineDatabaseDialectClass(Database database) { switch (database) { case DB2: return DB2Dialect.class; - case DERBY: return DerbyDialect.class; + case DERBY: return org.hibernate.dialect.DerbyDialect.class; case H2: return H2Dialect.class; case HSQL: return HSQLDialect.class; case INFORMIX: return InformixDialect.class; case MYSQL: return MySQLDialect.class; case ORACLE: return Oracle9iDialect.class; - case POSTGRESQL: return PostgreSQLDialect.class; + case POSTGRESQL: return org.hibernate.dialect.PostgreSQLDialect.class; case SQL_SERVER: return SQLServerDialect.class; case SYBASE: return org.hibernate.dialect.SybaseDialect.class; default: return null; diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index c4b2a11ea4d..47e488cf29d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -61,7 +61,7 @@ public abstract class TestPropertySourceUtils { /** * The name of the {@link MapPropertySource} created from inlined properties. * @since 4.1.5 - * @see {@link #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])} + * @see #addInlinedPropertiesToEnvironment */ public static final String INLINED_PROPERTIES_PROPERTY_SOURCE_NAME = "Inlined Test Properties"; @@ -224,8 +224,7 @@ public abstract class TestPropertySourceUtils { * @see TestPropertySource#properties * @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[]) */ - public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, - String... inlinedProperties) { + public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, String... inlinedProperties) { Assert.notNull(context, "context must not be null"); Assert.notNull(inlinedProperties, "inlinedProperties must not be null"); addInlinedPropertiesToEnvironment(context.getEnvironment(), inlinedProperties); @@ -252,13 +251,11 @@ public abstract class TestPropertySourceUtils { Assert.notNull(inlinedProperties, "inlinedProperties must not be null"); if (!ObjectUtils.isEmpty(inlinedProperties)) { if (logger.isDebugEnabled()) { - logger.debug("Adding inlined properties to environment: " - + ObjectUtils.nullSafeToString(inlinedProperties)); + logger.debug("Adding inlined properties to environment: " + ObjectUtils.nullSafeToString(inlinedProperties)); } MapPropertySource ps = (MapPropertySource) environment.getPropertySources().get(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME); if (ps == null) { - ps = new MapPropertySource(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME, - new LinkedHashMap()); + ps = new MapPropertySource(INLINED_PROPERTIES_PROPERTY_SOURCE_NAME, new LinkedHashMap()); environment.getPropertySources().addFirst(ps); } ps.getSource().putAll(convertInlinedPropertiesToMap(inlinedProperties)); @@ -285,21 +282,19 @@ public abstract class TestPropertySourceUtils { public static Map convertInlinedPropertiesToMap(String... inlinedProperties) { Assert.notNull(inlinedProperties, "inlinedProperties must not be null"); Map map = new LinkedHashMap(); - Properties props = new Properties(); + for (String pair : inlinedProperties) { if (!StringUtils.hasText(pair)) { continue; } - try { props.load(new StringReader(pair)); } - catch (Exception e) { - throw new IllegalStateException("Failed to load test environment property from [" + pair + "].", e); + catch (Exception ex) { + throw new IllegalStateException("Failed to load test environment property from [" + pair + "]", ex); } - Assert.state(props.size() == 1, "Failed to load exactly one test environment property from [" + pair + "]."); - + Assert.state(props.size() == 1, "Failed to load exactly one test environment property from [" + pair + "]"); for (String name : props.stringPropertyNames()) { map.put(name, props.getProperty(name)); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java index beee0a4f0f6..462bc56894c 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java @@ -719,28 +719,22 @@ public class Jackson2ObjectMapperBuilder { @SuppressWarnings("unchecked") private void registerWellKnownModulesIfAvailable(ObjectMapper objectMapper) { - // Java 7 java.nio.file.Path class present? - if (ClassUtils.isPresent("java.nio.file.Path", this.moduleClassLoader)) { - try { - Class jdk7Module = (Class) - ClassUtils.forName("com.fasterxml.jackson.datatype.jdk7.Jdk7Module", this.moduleClassLoader); - objectMapper.registerModule(BeanUtils.instantiate(jdk7Module)); - } - catch (ClassNotFoundException ex) { - // jackson-datatype-jdk7 not available - } + try { + Class jdk7Module = (Class) + ClassUtils.forName("com.fasterxml.jackson.datatype.jdk7.Jdk7Module", this.moduleClassLoader); + objectMapper.registerModule(BeanUtils.instantiate(jdk7Module)); + } + catch (ClassNotFoundException ex) { + // jackson-datatype-jdk7 not available } - // Java 8 java.util.Optional class present? - if (ClassUtils.isPresent("java.util.Optional", this.moduleClassLoader)) { - try { - Class jdk8Module = (Class) - ClassUtils.forName("com.fasterxml.jackson.datatype.jdk8.Jdk8Module", this.moduleClassLoader); - objectMapper.registerModule(BeanUtils.instantiate(jdk8Module)); - } - catch (ClassNotFoundException ex) { - // jackson-datatype-jdk8 not available - } + try { + Class jdk8Module = (Class) + ClassUtils.forName("com.fasterxml.jackson.datatype.jdk8.Jdk8Module", this.moduleClassLoader); + objectMapper.registerModule(BeanUtils.instantiate(jdk8Module)); + } + catch (ClassNotFoundException ex) { + // jackson-datatype-jdk8 not available } // Java 8 java.time package present? @@ -812,7 +806,7 @@ public class Jackson2ObjectMapperBuilder { return new XmlMapper(new XmlFactory(xmlInputFactory()), module); } - private static final XMLInputFactory xmlInputFactory() { + private static XMLInputFactory xmlInputFactory() { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); diff --git a/spring-web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java b/spring-web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java index 00914135afe..b43d0ec7047 100644 --- a/spring-web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java +++ b/spring-web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.lang.UsesJava7; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -190,7 +189,6 @@ public abstract class AbstractJaxWsServiceExporter implements BeanFactoryAware, * @see Endpoint#create(Object) * @see Endpoint#create(String, Object) */ - @UsesJava7 // optional use of Endpoint#create with WebServiceFeature[] protected Endpoint createEndpoint(Object bean) { if (this.endpointFeatures != null || this.webServiceFeatures != null) { WebServiceFeature[] endpointFeaturesToUse = this.endpointFeatures; diff --git a/spring-web/src/main/java/org/springframework/remoting/jaxws/LocalJaxWsServiceFactory.java b/spring-web/src/main/java/org/springframework/remoting/jaxws/LocalJaxWsServiceFactory.java index fd423cf30c0..b20fbab68c3 100644 --- a/spring-web/src/main/java/org/springframework/remoting/jaxws/LocalJaxWsServiceFactory.java +++ b/spring-web/src/main/java/org/springframework/remoting/jaxws/LocalJaxWsServiceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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,6 @@ import javax.xml.ws.WebServiceFeature; import javax.xml.ws.handler.HandlerResolver; import org.springframework.core.io.Resource; -import org.springframework.lang.UsesJava7; import org.springframework.util.Assert; /** @@ -147,7 +146,6 @@ public class LocalJaxWsServiceFactory { * @see #setServiceName * @see #setWsdlDocumentUrl */ - @UsesJava7 // optional use of Service#create with WebServiceFeature[] public Service createJaxWsService() { Assert.notNull(this.serviceName, "No service name specified"); Service service; diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/CrossOrigin.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/CrossOrigin.java index 76aacd0a473..a859be9efa0 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/CrossOrigin.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/CrossOrigin.java @@ -33,9 +33,6 @@ import org.springframework.core.annotation.AliasFor; * {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the * {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter} * pair which are the default in the MVC Java config and the MVC namespace. - * In particular {@code @CrossOrigin} is not supported with the - * {@code DefaultAnnotationHandlerMapping}-{@code AnnotationMethodHandlerAdapter} - * pair both of which are also deprecated. * * @author Russell Allen * @author Sebastien Deleuze diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/PathVariable.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/PathVariable.java index 2d64574d0ec..6a4ba439672 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/PathVariable.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/PathVariable.java @@ -35,7 +35,6 @@ import java.lang.annotation.Target; * @since 3.0 * @see RequestMapping * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter */ @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestBody.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestBody.java index 9a51146c48f..08d830fc202 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestBody.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestBody.java @@ -37,7 +37,6 @@ import org.springframework.http.converter.HttpMessageConverter; * @see RequestHeader * @see ResponseBody * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter */ @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java index 0e756a2c1e1..4628023bb8a 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMapping.java @@ -235,19 +235,8 @@ import org.springframework.core.annotation.AliasFor; *

    NOTE: {@code @RequestMapping} will only be processed if an * an appropriate {@code HandlerMapping}-{@code HandlerAdapter} pair * is configured. If you are defining custom {@code HandlerMappings} or - * {@code HandlerAdapters}, then you need to add - * {@code DefaultAnnotationHandlerMapping} and - * {@code AnnotationMethodHandlerAdapter} to your configuration.. - * - *

    NOTE: Spring 3.1 introduced a new set of support classes for - * {@code @RequestMapping} methods in Servlet environments called - * {@code RequestMappingHandlerMapping} and - * {@code RequestMappingHandlerAdapter}. They are recommended for use and - * even required to take advantage of new features in Spring MVC 3.1 (search - * {@literal "@MVC 3.1-only"} in this source file) and going forward. - * The new support classes are enabled by default from the MVC namespace and - * with use of the MVC Java config ({@code @EnableWebMvc}) but must be - * configured explicitly if using neither. + * {@code HandlerAdapters}, then you need to add {@code RequestMappingHandlerMapping} + * and {@code RequestMappingHandlerAdapter} to your configuration.. * *

    NOTE: When using controller interfaces (e.g. for AOP proxying), * make sure to consistently put all your mapping annotations - such as diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java index 2287f65264f..aed21ae3d1e 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java @@ -36,9 +36,6 @@ import org.springframework.stereotype.Controller; * {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the * {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter} * pair which are the default in the MVC Java config and the MVC namespace. - * In particular {@code @RestController} is not supported with the - * {@code DefaultAnnotationHandlerMapping}-{@code AnnotationMethodHandlerAdapter} - * pair both of which are also deprecated. * * @author Rossen Stoyanchev * @author Sam Brannen diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java index 29b080762b5..7ab99fea10e 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestControllerAdvice.java @@ -38,9 +38,6 @@ import org.springframework.core.annotation.AliasFor; * {@code HandlerMapping}-{@code HandlerAdapter} pair is configured such as the * {@code RequestMappingHandlerMapping}-{@code RequestMappingHandlerAdapter} pair * which are the default in the MVC Java config and the MVC namespace. - * In particular {@code @RestControllerAdvice} is not supported with the - * {@code DefaultAnnotationHandlerMapping}-{@code AnnotationMethodHandlerAdapter} - * pair both of which are also deprecated. * * @author Rossen Stoyanchev * @since 4.3 diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebArgumentResolver.java index 2ab5731a878..4fcc9c2e0b5 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ import org.springframework.web.context.request.NativeWebRequest; * * @author Juergen Hoeller * @since 2.5.2 - * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#setCustomArgumentResolvers + * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#setCustomArgumentResolvers */ public interface WebArgumentResolver { diff --git a/spring-web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java b/spring-web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java index 2d7c4053ce8..052314f238e 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,7 +79,6 @@ public abstract class AbstractRequestAttributesScope implements Scope { * {@link RequestAttributes} constant * @see RequestAttributes#SCOPE_REQUEST * @see RequestAttributes#SCOPE_SESSION - * @see RequestAttributes#SCOPE_GLOBAL_SESSION */ protected abstract int getScope(); diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java index 774c8aeaf25..27fa024ad80 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java @@ -64,9 +64,7 @@ public abstract class WebAsyncUtils { /** * Create an AsyncWebRequest instance. By default, an instance of - * {@link StandardServletAsyncWebRequest} gets created when running in - * Servlet 3.0 (or higher) environment - as a fallback, an instance - * of {@link NoSupportAsyncWebRequest} will be returned. + * {@link StandardServletAsyncWebRequest} gets created. * @param request the current request * @param response the current response * @return an AsyncWebRequest instance (never {@code null}) diff --git a/spring-web/src/main/java/org/springframework/web/method/HandlerMethodSelector.java b/spring-web/src/main/java/org/springframework/web/method/HandlerMethodSelector.java deleted file mode 100644 index 82acd2c3bda..00000000000 --- a/spring-web/src/main/java/org/springframework/web/method/HandlerMethodSelector.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2002-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.method; - -import java.lang.reflect.Method; -import java.util.Set; - -import org.springframework.core.MethodIntrospector; -import org.springframework.util.ReflectionUtils.MethodFilter; - -/** - * Defines the algorithm for searching handler methods exhaustively including interfaces and parent - * classes while also dealing with parameterized methods as well as interface and class-based proxies. - * - * @author Rossen Stoyanchev - * @since 3.1 - * @deprecated as of Spring 4.2.3, in favor of the generalized and refined {@link MethodIntrospector} - */ -@Deprecated -public abstract class HandlerMethodSelector { - - /** - * Select handler methods for the given handler type. - *

    Callers define handler methods of interest through the {@link MethodFilter} parameter. - * @param handlerType the handler type to search handler methods on - * @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest - * @return the selected methods, or an empty set - * @see MethodIntrospector#selectMethods(Class, MethodFilter) - */ - public static Set selectMethods(Class handlerType, MethodFilter handlerMethodFilter) { - return MethodIntrospector.selectMethods(handlerType, handlerMethodFilter); - } - -} diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java index 81030d3bf2b..8c82eefdd58 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java @@ -45,7 +45,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; * constructor (and then added to the model). Once created the attribute is * populated via data binding to Servlet request parameters. Validation may be * applied if the argument is annotated with {@code @javax.validation.Valid}. - * or {@link @Validated}. + * or Spring's own {@code @org.springframework.validation.annotation.Validated}. * *

    When this handler is created with {@code annotationNotRequired=true} * any non-simple type argument and return value is regarded as a model diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java b/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java index 14a412b2f86..d7ca57f1997 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/MultipartResolutionDelegate.java @@ -98,13 +98,13 @@ public abstract class MultipartResolutionDelegate { } } else if (Part.class == parameter.getNestedParameterType()) { - return (isMultipart ? RequestPartResolver.resolvePart(request, name) : null); + return (isMultipart ? resolvePart(request, name) : null); } else if (isPartCollection(parameter)) { - return (isMultipart ? RequestPartResolver.resolvePartList(request, name) : null); + return (isMultipart ? resolvePartList(request, name) : null); } else if (isPartArray(parameter)) { - return (isMultipart ? RequestPartResolver.resolvePartArray(request, name) : null); + return (isMultipart ? resolvePartArray(request, name) : null); } else { return UNRESOLVABLE; @@ -138,37 +138,30 @@ public abstract class MultipartResolutionDelegate { return null; } + private static Part resolvePart(HttpServletRequest servletRequest, String name) throws Exception { + return servletRequest.getPart(name); + } - /** - * Inner class to avoid hard-coded dependency on Servlet 3.0 Part type... - */ - private static class RequestPartResolver { - - public static Object resolvePart(HttpServletRequest servletRequest, String name) throws Exception { - return servletRequest.getPart(name); - } - - public static Object resolvePartList(HttpServletRequest servletRequest, String name) throws Exception { - Collection parts = servletRequest.getParts(); - List result = new ArrayList(parts.size()); - for (Part part : parts) { - if (part.getName().equals(name)) { - result.add(part); - } + private static List resolvePartList(HttpServletRequest servletRequest, String name) throws Exception { + Collection parts = servletRequest.getParts(); + List result = new ArrayList(parts.size()); + for (Part part : parts) { + if (part.getName().equals(name)) { + result.add(part); } - return result; } + return result; + } - public static Object resolvePartArray(HttpServletRequest servletRequest, String name) throws Exception { - Collection parts = servletRequest.getParts(); - List result = new ArrayList(parts.size()); - for (Part part : parts) { - if (part.getName().equals(name)) { - result.add(part); - } + private static Part[] resolvePartArray(HttpServletRequest servletRequest, String name) throws Exception { + Collection parts = servletRequest.getParts(); + List result = new ArrayList(parts.size()); + for (Part part : parts) { + if (part.getName().equals(name)) { + result.add(part); } - return result.toArray(new Part[result.size()]); } + return result.toArray(new Part[result.size()]); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index e18f57e26d5..b1c5274dcaf 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -74,7 +74,7 @@ import org.springframework.web.util.WebUtils; *

  • It can use any {@link HandlerMapping} implementation - pre-built or provided as part * of an application - to control the routing of requests to handler objects. Default is * {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping} and - * {@link org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping}. + * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping}. * HandlerMapping objects can be defined as beans in the servlet's application context, * implementing the HandlerMapping interface, overriding the default HandlerMapping if * present. HandlerMappings can be given any bean name (they are tested by type). @@ -84,7 +84,7 @@ import org.springframework.web.util.WebUtils; * {@link org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter}, for Spring's * {@link org.springframework.web.HttpRequestHandler} and * {@link org.springframework.web.servlet.mvc.Controller} interfaces, respectively. A default - * {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter} + * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter} * will be registered as well. HandlerAdapter objects can be added as beans in the * application context, overriding the default HandlerAdapters. Like HandlerMappings, * HandlerAdapters can be given any bean name (they are tested by type). @@ -92,7 +92,7 @@ import org.springframework.web.util.WebUtils; *
  • The dispatcher's exception resolution strategy can be specified via a * {@link HandlerExceptionResolver}, for example mapping certain exceptions to error pages. * Default are - * {@link org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver}, + * {@link org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver}, * {@link org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver}, and * {@link org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver}. * These HandlerExceptionResolvers can be overridden through the application context. @@ -131,7 +131,7 @@ import org.springframework.web.util.WebUtils; * {@code HandlerAdapter} (for method-level annotations) is present in the dispatcher. * This is the case by default. However, if you are defining custom {@code HandlerMappings} * or {@code HandlerAdapters}, then you need to make sure that a corresponding custom - * {@code DefaultAnnotationHandlerMapping} and/or {@code AnnotationMethodHandlerAdapter} + * {@code RequestMappingHandlerMapping} and/or {@code RequestMappingHandlerAdapter} * is defined as well - provided that you intend to use {@code @RequestMapping}. * *

    A web application can define any number of DispatcherServlets. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerMapping.java index 117bff35889..00d26677e99 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import javax.servlet.http.HttpServletRequest; * *

    This class can be implemented by application developers, although this is not * necessary, as {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping} - * and {@link org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping} + * and {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping} * are included in the framework. The former is the default if no * HandlerMapping bean is registered in the application context. * @@ -49,7 +49,7 @@ import javax.servlet.http.HttpServletRequest; * @see org.springframework.core.Ordered * @see org.springframework.web.servlet.handler.AbstractHandlerMapping * @see org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping - * @see org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping + * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping */ public interface HandlerMapping { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java index 397c179b039..e6e6033a2d0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2016 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,9 +28,9 @@ import org.springframework.util.StringUtils; * *

    This is the default implementation used by the * {@link org.springframework.web.servlet.DispatcherServlet}, along with - * {@link org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping} - * (on Java 5 and higher). Alternatively, {@link SimpleUrlHandlerMapping} allows for - * customizing a handler mapping declaratively. + * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping}. + * Alternatively, {@link SimpleUrlHandlerMapping} allows for customizing a + * handler mapping declaratively. * *

    The mapping is from URL to bean name. Thus an incoming URL "/foo" would map * to a handler named "/foo", or to "/foo /foo2" in case of multiple mappings to diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java index f216e9f6108..6fcd7c8924b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.SimpleLocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; -import org.springframework.lang.UsesJava7; import org.springframework.util.StringUtils; import org.springframework.web.servlet.LocaleContextResolver; import org.springframework.web.servlet.LocaleResolver; @@ -242,7 +241,6 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte * @return the corresponding {@code Locale} instance * @since 4.3 */ - @UsesJava7 protected Locale parseLocaleValue(String locale) { return (isLanguageTagCompliant() ? Locale.forLanguageTag(locale) : StringUtils.parseLocaleString(locale)); } @@ -256,7 +254,6 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte * @return a String representation for the given locale * @since 4.3 */ - @UsesJava7 protected String toLocaleValue(Locale locale) { return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString()); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java index 7642bcd0db7..3bfcbed9e35 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.lang.UsesJava7; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.servlet.LocaleResolver; @@ -183,7 +182,6 @@ public class LocaleChangeInterceptor extends HandlerInterceptorAdapter { * @return the corresponding {@code Locale} instance * @since 4.3 */ - @UsesJava7 protected Locale parseLocaleValue(String locale) { return (isLanguageTagCompliant() ? Locale.forLanguageTag(locale) : StringUtils.parseLocaleString(locale)); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CompletionStageReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CompletionStageReturnValueHandler.java deleted file mode 100644 index 7ec8e7c0f92..00000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CompletionStageReturnValueHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2002-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.mvc.method.annotation; - -import java.util.concurrent.CompletionStage; -import java.util.function.Consumer; -import java.util.function.Function; - -import org.springframework.core.MethodParameter; -import org.springframework.lang.UsesJava8; -import org.springframework.web.context.request.NativeWebRequest; -import org.springframework.web.context.request.async.DeferredResult; -import org.springframework.web.context.request.async.WebAsyncUtils; -import org.springframework.web.method.support.AsyncHandlerMethodReturnValueHandler; -import org.springframework.web.method.support.ModelAndViewContainer; - -/** - * Handles return values of type {@link CompletionStage} (implemented by - * {@link java.util.concurrent.CompletableFuture} for example). - * - * @author Sebastien Deleuze - * @since 4.2 - * - * @deprecated as of 4.3 {@link DeferredResultMethodReturnValueHandler} supports - * CompletionStage return values via an adapter mechanism. - */ -@Deprecated -@UsesJava8 -public class CompletionStageReturnValueHandler implements AsyncHandlerMethodReturnValueHandler { - - @Override - public boolean supportsReturnType(MethodParameter returnType) { - return CompletionStage.class.isAssignableFrom(returnType.getParameterType()); - } - - @Override - public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) { - return (returnValue != null && returnValue instanceof CompletionStage); - } - - @Override - public void handleReturnValue(Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { - - if (returnValue == null) { - mavContainer.setRequestHandled(true); - return; - } - - final DeferredResult deferredResult = new DeferredResult(); - WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer); - - @SuppressWarnings("unchecked") - CompletionStage future = (CompletionStage) returnValue; - future.thenAccept(new Consumer() { - @Override - public void accept(Object result) { - deferredResult.setResult(result); - } - }); - future.exceptionally(new Function() { - @Override - public Object apply(Throwable ex) { - deferredResult.setErrorResult(ex); - return null; - } - }); - } - -} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java index 6361c77ff13..b51486a8632 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java @@ -22,9 +22,7 @@ import java.util.concurrent.CompletionStage; import java.util.function.BiFunction; import org.springframework.core.MethodParameter; -import org.springframework.lang.UsesJava8; import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureCallback; import org.springframework.web.context.request.NativeWebRequest; @@ -50,9 +48,7 @@ public class DeferredResultMethodReturnValueHandler implements AsyncHandlerMetho this.adapterMap = new HashMap, DeferredResultAdapter>(5); this.adapterMap.put(DeferredResult.class, new SimpleDeferredResultAdapter()); this.adapterMap.put(ListenableFuture.class, new ListenableFutureAdapter()); - if (ClassUtils.isPresent("java.util.concurrent.CompletionStage", getClass().getClassLoader())) { - this.adapterMap.put(CompletionStage.class, new CompletionStageAdapter()); - } + this.adapterMap.put(CompletionStage.class, new CompletionStageAdapter()); } @@ -114,6 +110,7 @@ public class DeferredResultMethodReturnValueHandler implements AsyncHandlerMetho } } + /** * Adapter for {@code ListenableFuture} return values. */ @@ -137,10 +134,10 @@ public class DeferredResultMethodReturnValueHandler implements AsyncHandlerMetho } } + /** * Adapter for {@code CompletionStage} return values. */ - @UsesJava8 private static class CompletionStageAdapter implements DeferredResultAdapter { @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ListenableFutureReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ListenableFutureReturnValueHandler.java deleted file mode 100644 index 3a3706f06ba..00000000000 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ListenableFutureReturnValueHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2002-2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.mvc.method.annotation; - -import org.springframework.core.MethodParameter; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; -import org.springframework.web.context.request.NativeWebRequest; -import org.springframework.web.context.request.async.DeferredResult; -import org.springframework.web.context.request.async.WebAsyncUtils; -import org.springframework.web.method.support.AsyncHandlerMethodReturnValueHandler; -import org.springframework.web.method.support.ModelAndViewContainer; - -/** - * Handles return values of type - * {@link org.springframework.util.concurrent.ListenableFuture}. - * - * @author Rossen Stoyanchev - * @since 4.1 - * - * @deprecated as of 4.3 {@link DeferredResultMethodReturnValueHandler} supports - * ListenableFuture return values via an adapter mechanism. - */ -@Deprecated -public class ListenableFutureReturnValueHandler implements AsyncHandlerMethodReturnValueHandler { - - @Override - public boolean supportsReturnType(MethodParameter returnType) { - return ListenableFuture.class.isAssignableFrom(returnType.getParameterType()); - } - - @Override - public boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType) { - return (returnValue != null && returnValue instanceof ListenableFuture); - } - - @Override - public void handleReturnValue(Object returnValue, MethodParameter returnType, - ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { - - if (returnValue == null) { - mavContainer.setRequestHandled(true); - return; - } - - final DeferredResult deferredResult = new DeferredResult(); - WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer); - - ListenableFuture future = (ListenableFuture) returnValue; - future.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(Object result) { - deferredResult.setResult(result); - } - @Override - public void onFailure(Throwable ex) { - deferredResult.setErrorResult(ex); - } - }); - } - -} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java index d449b45d71b..bf2293630d9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java @@ -38,8 +38,8 @@ import org.springframework.cglib.proxy.Enhancer; import org.springframework.cglib.proxy.Factory; import org.springframework.cglib.proxy.MethodProxy; import org.springframework.core.DefaultParameterNameDiscoverer; -import org.springframework.core.MethodParameter; import org.springframework.core.MethodIntrospector; +import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.SynthesizingMethodParameter; @@ -778,7 +778,6 @@ public class MvcUriComponentsBuilder { } /** - * @see #MethodArgumentBuilder(Class, Method) * @deprecated as of 4.2, this is deprecated in favor of alternative constructors * that accept a controllerType argument */ diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java index d78d77de9db..d2b58c60e78 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java @@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletRequest; import org.springframework.core.MethodParameter; import org.springframework.http.HttpInputMessage; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.UsesJava8; import org.springframework.validation.BindingResult; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.WebDataBinder; @@ -158,7 +157,13 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM } } if (parameter.isOptional()) { - arg = OptionalResolver.resolveValue(arg); + if (arg == null || (arg instanceof Collection && ((Collection) arg).isEmpty()) || + (arg instanceof Object[] && ((Object[]) arg).length == 0)) { + arg = Optional.empty(); + } + else { + arg = Optional.of(arg); + } } return arg; @@ -177,20 +182,4 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM return partName; } - - /** - * Inner class to avoid hard-coded dependency on Java 8 Optional type... - */ - @UsesJava8 - private static class OptionalResolver { - - public static Object resolveValue(Object value) { - if (value == null || (value instanceof Collection && ((Collection) value).isEmpty()) || - (value instanceof Object[] && ((Object[]) value).length == 0)) { - return Optional.empty(); - } - return Optional.of(value); - } - } - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java index 1ec50e65ee0..a87660869bd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2016 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 javax.servlet.http.HttpSession; import org.springframework.core.MethodParameter; import org.springframework.http.HttpMethod; -import org.springframework.lang.UsesJava8; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.ServletWebRequest; @@ -131,7 +130,6 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume /** * Inner class to avoid a hard-coded dependency on Java 8's {@link java.time.ZoneId}. */ - @UsesJava8 private static class ZoneIdResolver { public static Object resolveZoneId(HttpServletRequest request) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java index 48163090a75..a7e12067b81 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java @@ -142,22 +142,6 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver; import static org.junit.Assert.*; /** - * The origin of this test class is {@link ServletAnnotationControllerHandlerMethodTests}. - * - * Tests in this class run against the {@link HandlerMethod} infrastructure: - *
      - *
    • RequestMappingHandlerMapping - *
    • RequestMappingHandlerAdapter - *
    • ExceptionHandlerExceptionResolver - *
    - * - *

    Rather than against the existing infrastructure: - *

      - *
    • DefaultAnnotationHandlerMapping - *
    • AnnotationMethodHandlerAdapter - *
    • AnnotationMethodHandlerExceptionResolver - *
    - * * @author Rossen Stoyanchev */ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServletHandlerMethodTests { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java index 26a0a19280b..0627629acb9 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/UriTemplateServletAnnotationControllerHandlerMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.GenericWebApplicationContext; -import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.View; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.view.AbstractView; @@ -54,20 +53,6 @@ import org.springframework.web.servlet.view.AbstractView; import static org.junit.Assert.*; /** - * Tests in this class run against the {@link HandlerMethod} infrastructure: - *
      - *
    • RequestMappingHandlerMapping - *
    • RequestMappingHandlerAdapter - *
    • ExceptionHandlerExceptionResolver - *
    - * - *

    Rather than against the existing infrastructure: - *

      - *
    • DefaultAnnotationHandlerMapping - *
    • AnnotationMethodHandlerAdapter - *
    • AnnotationMethodHandlerExceptionResolver - *
    - * * @author Rossen Stoyanchev * @since 3.1 */ diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java index 2dbd8157064..8c3f7833318 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/StandardWebSocketClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.Callable; - import javax.websocket.ClientEndpointConfig; import javax.websocket.ClientEndpointConfig.Configurator; import javax.websocket.ContainerProvider; @@ -39,7 +38,6 @@ import org.springframework.core.task.AsyncListenableTaskExecutor; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.http.HttpHeaders; -import org.springframework.lang.UsesJava7; import org.springframework.util.Assert; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureTask; @@ -51,7 +49,6 @@ import org.springframework.web.socket.adapter.standard.StandardWebSocketSession; import org.springframework.web.socket.adapter.standard.WebSocketToStandardExtensionAdapter; import org.springframework.web.socket.client.AbstractWebSocketClient; - /** * A WebSocketClient based on standard Java WebSocket API. * @@ -172,7 +169,6 @@ public class StandardWebSocketClient extends AbstractWebSocketClient { return result; } - @UsesJava7 // fallback to InetAddress.getLoopbackAddress() private InetAddress getLocalHost() { try { return InetAddress.getLocalHost(); diff --git a/src/asciidoc/integration.adoc b/src/asciidoc/integration.adoc index f0a12c90b29..a6ed72d8206 100644 --- a/src/asciidoc/integration.adoc +++ b/src/asciidoc/integration.adoc @@ -1290,7 +1290,7 @@ a better feel for its functionality Concrete implementations for the main media (mime) types are provided in the framework and are registered by default with the `RestTemplate` on the client-side and with -`AnnotationMethodHandlerAdapter` on the server-side. +`RequestMethodHandlerAdapter` on the server-side. The implementations of ``HttpMessageConverter``s are described in the following sections. For all converters a default media type is used but can be overridden by setting the diff --git a/src/asciidoc/web-mvc.adoc b/src/asciidoc/web-mvc.adoc index 3c285dfceb8..80858a547ce 100644 --- a/src/asciidoc/web-mvc.adoc +++ b/src/asciidoc/web-mvc.adoc @@ -2132,7 +2132,7 @@ controller-specific tweaking of the binding rules. To externalize data binding initialization, you can provide a custom implementation of the `WebBindingInitializer` interface, which you then enable by supplying a custom bean -configuration for an `AnnotationMethodHandlerAdapter`, thus overriding the default +configuration for an `RequestMappingHandlerAdapter`, thus overriding the default configuration. The following example from the PetClinic application shows a configuration using a