Avoid defensive checks against Java 8 API (java.util.Optional etc)

This commit also fixes broken javadoc links and code references.

Issue: SPR-13188
This commit is contained in:
Juergen Hoeller
2016-07-05 02:08:59 +02:00
parent adb935db79
commit 51252ebbca
98 changed files with 290 additions and 1232 deletions

View File

@@ -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<? extends Module> jdk7Module = (Class<? extends Module>)
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<? extends Module> jdk7Module = (Class<? extends Module>)
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<? extends Module> jdk8Module = (Class<? extends Module>)
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<? extends Module> jdk8Module = (Class<? extends Module>)
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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -235,19 +235,8 @@ import org.springframework.core.annotation.AliasFor;
* <p><b>NOTE:</b> {@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.</code>.
*
* <p><b>NOTE:</b> 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.</code>.
*
* <p><b>NOTE:</b> When using controller interfaces (e.g. for AOP proxying),
* make sure to consistently put <i>all</i> your mapping annotations - such as

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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();

View File

@@ -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})

View File

@@ -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.
* <p>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<Method> selectMethods(Class<?> handlerType, MethodFilter handlerMethodFilter) {
return MethodIntrospector.selectMethods(handlerType, handlerMethodFilter);
}
}

View File

@@ -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}.
*
* <p>When this handler is created with {@code annotationNotRequired=true}
* any non-simple type argument and return value is regarded as a model

View File

@@ -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<Part> parts = servletRequest.getParts();
List<Part> result = new ArrayList<Part>(parts.size());
for (Part part : parts) {
if (part.getName().equals(name)) {
result.add(part);
}
private static List<Part> resolvePartList(HttpServletRequest servletRequest, String name) throws Exception {
Collection<Part> parts = servletRequest.getParts();
List<Part> result = new ArrayList<Part>(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<Part> parts = servletRequest.getParts();
List<Part> result = new ArrayList<Part>(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<Part> parts = servletRequest.getParts();
List<Part> result = new ArrayList<Part>(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()]);
}
}