diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyMatches.java b/spring-beans/src/main/java/org/springframework/beans/PropertyMatches.java index 87cea92830..87ccf2a95c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyMatches.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyMatches.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. @@ -30,8 +30,8 @@ import org.springframework.util.StringUtils; * Helper class for calculating property matches, according to a configurable * distance. Provide the list of potential matches and an easy way to generate * an error message. Works for both java bean properties and fields. - *

- * Mainly for use within the framework and in particular the binding facility + * + *

Mainly for use within the framework and in particular the binding facility. * * @author Alef Arendsen * @author Arjen Poutsma @@ -43,14 +43,12 @@ import org.springframework.util.StringUtils; */ public abstract class PropertyMatches { - //--------------------------------------------------------------------- - // Static section - //--------------------------------------------------------------------- - /** Default maximum property distance: 2 */ public static final int DEFAULT_MAX_DISTANCE = 2; + // Static factory methods + /** * Create PropertyMatches for the given bean property. * @param propertyName the name of the property to find possible matches for @@ -90,9 +88,7 @@ public abstract class PropertyMatches { } - //--------------------------------------------------------------------- - // Instance section - //--------------------------------------------------------------------- + // Instance state private final String propertyName; @@ -107,18 +103,19 @@ public abstract class PropertyMatches { this.possibleMatches = possibleMatches; } + /** * Return the name of the requested property. */ public String getPropertyName() { - return propertyName; + return this.propertyName; } /** * Return the calculated possible matches. */ public String[] getPossibleMatches() { - return possibleMatches; + return this.possibleMatches; } /** @@ -127,6 +124,9 @@ public abstract class PropertyMatches { */ public abstract String buildErrorMessage(); + + // Implementation support for subclasses + protected void appendHintMessage(StringBuilder msg) { msg.append("Did you mean "); for (int i = 0; i < this.possibleMatches.length; i++) { @@ -184,9 +184,12 @@ public abstract class PropertyMatches { return d[s1.length()][s2.length()]; } + + // Concrete subclasses + private static class BeanPropertyMatches extends PropertyMatches { - private BeanPropertyMatches(String propertyName, Class beanClass, int maxDistance) { + public BeanPropertyMatches(String propertyName, Class beanClass, int maxDistance) { super(propertyName, calculateMatches(propertyName, BeanUtils.getPropertyDescriptors(beanClass), maxDistance)); } @@ -231,12 +234,12 @@ public abstract class PropertyMatches { } return msg.toString(); } - } + private static class FieldPropertyMatches extends PropertyMatches { - private FieldPropertyMatches(String propertyName, Class beanClass, int maxDistance) { + public FieldPropertyMatches(String propertyName, Class beanClass, int maxDistance) { super(propertyName, calculateMatches(propertyName, beanClass, maxDistance)); } @@ -255,7 +258,6 @@ public abstract class PropertyMatches { return StringUtils.toStringArray(candidates); } - @Override public String buildErrorMessage() { String propertyName = getPropertyName(); @@ -270,7 +272,6 @@ public abstract class PropertyMatches { } return msg.toString(); } - } } diff --git a/spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java b/spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java index 5cf2e81746..2bba3f2c61 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.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. @@ -27,12 +27,12 @@ import org.springframework.core.convert.support.GenericConversionService; /** * A factory providing convenient access to a ConversionService configured with - * converters appropriate for most environments. Set the {@link #setConverters - * "converters"} property to supplement the default converters. + * converters appropriate for most environments. Set the + * {@link #setConverters "converters"} property to supplement the default converters. * - *

This implementation creates a {@link DefaultConversionService}. Subclasses - * may override {@link #createConversionService()} in order to return a - * {@link GenericConversionService} instance of their choosing. + *

This implementation creates a {@link DefaultConversionService}. + * Subclasses may override {@link #createConversionService()} in order to return + * a {@link GenericConversionService} instance of their choosing. * *

Like all {@code FactoryBean} implementations, this class is suitable for * use when configuring a Spring application context using Spring {@code } diff --git a/spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java b/spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java index 48d8eb7ffb..964b94aafb 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.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. @@ -49,7 +49,6 @@ import org.springframework.util.CollectionUtils; * @author Rob Harrop * @author Juergen Hoeller * @since 1.2 - * @see FactoryBean * @see JMXConnectorServer * @see MBeanServer */ diff --git a/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java b/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java index 51ff49e148..a0c7f4de3d 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-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. @@ -206,8 +206,8 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces @Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ConfigurableBeanFactory)) { - throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with a BeanFactory " - + "which does not implement ConfigurableBeanFactory: " + beanFactory.getClass()); + throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with " + + "non-ConfigurableBeanFactory: " + beanFactory.getClass()); } this.beanFactory = (ConfigurableBeanFactory) beanFactory; diff --git a/spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java b/spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java index f00ddde35d..493b65178f 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.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,13 +29,12 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** - * * @author Stephane Nicoll */ public class ExpressionCachingIntegrationTests { + @Test // SPR-11692 @SuppressWarnings("unchecked") - @Test // SPR-11692 public void expressionIsCacheBasedOnActualMethod() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(SharedConfig.class, Spr11692Config.class); @@ -50,9 +49,9 @@ public class ExpressionCachingIntegrationTests { } - @Configuration static class Spr11692Config { + @Bean public BaseDao userDao() { return new UserDaoImpl(); @@ -65,11 +64,14 @@ public class ExpressionCachingIntegrationTests { } - private static interface BaseDao { + private interface BaseDao { + T persist(T t); } + private static class UserDaoImpl implements BaseDao { + @Override @CachePut(value = "users", key = "#user.id") public User persist(User user) { @@ -77,7 +79,9 @@ public class ExpressionCachingIntegrationTests { } } + private static class OrderDaoImpl implements BaseDao { + @Override @CachePut(value = "orders", key = "#order.id") public Order persist(Order order) { @@ -85,35 +89,41 @@ public class ExpressionCachingIntegrationTests { } } + private static class User { + private final String id; - private User(String id) { + public User(String id) { this.id = id; } @SuppressWarnings("unused") public String getId() { - return id; + return this.id; } } + private static class Order { + private final String id; - private Order(String id) { + public Order(String id) { this.id = id; } @SuppressWarnings("unused") public String getId() { - return id; + return this.id; } } + @Configuration @EnableCaching static class SharedConfig extends CachingConfigurerSupport { + @Override @Bean public CacheManager cacheManager() { diff --git a/spring-core/src/main/java/org/springframework/core/convert/Property.java b/spring-core/src/main/java/org/springframework/core/convert/Property.java index 84258e9d96..0da18ee69d 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/Property.java +++ b/spring-core/src/main/java/org/springframework/core/convert/Property.java @@ -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. @@ -72,7 +72,7 @@ public final class Property { this.readMethod = readMethod; this.writeMethod = writeMethod; this.methodParameter = resolveMethodParameter(); - this.name = (name == null ? resolveName() : name); + this.name = (name != null ? name : resolveName()); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java b/spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java index 1806afd218..ce6af12125 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java @@ -32,6 +32,7 @@ abstract class ConversionUtils { public static Object invokeConverter(GenericConverter converter, Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + try { return converter.convert(source, sourceType, targetType); } @@ -43,7 +44,9 @@ abstract class ConversionUtils { } } - public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeDescriptor targetElementType, ConversionService conversionService) { + public static boolean canConvertElements(TypeDescriptor sourceElementType, TypeDescriptor targetElementType, + ConversionService conversionService) { + if (targetElementType == null) { // yes return true; @@ -57,11 +60,11 @@ abstract class ConversionUtils { return true; } else if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) { - // maybe; + // maybe return true; } else { - // no; + // no return false; } } 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 9432b44edf..6bf88279dd 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 @@ -67,8 +67,8 @@ public class GenericConversionService implements ConfigurableConversionService { private static final GenericConverter NO_OP_CONVERTER = new NoOpConverter("NO_OP"); /** - * Used as a cache entry when no converter is available. This converter is never - * returned. + * Used as a cache entry when no converter is available. + * This converter is never returned. */ private static final GenericConverter NO_MATCH = new NoOpConverter("NO_MATCH"); diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java index 076e7b37ed..bf982d6e24 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.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. @@ -151,8 +151,7 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory, */ @Override public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { - Assert.state(this.taskExecutor != null, - "Asynchronous execution requires an AsyncTaskExecutor to be set"); + Assert.state(this.taskExecutor != null, "Asynchronous execution requires TaskExecutor to be set"); HttpURLConnection connection = openConnection(uri.toURL(), this.proxy); prepareConnection(connection, httpMethod.name()); diff --git a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java index 659030af11..becfcefd1e 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.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. @@ -44,14 +44,14 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public class UriTemplate implements Serializable { + private final String uriTemplate; + private final UriComponents uriComponents; private final List variableNames; private final Pattern matchPattern; - private final String uriTemplate; - /** * Construct a new {@code UriTemplate} with the given URI String. @@ -173,7 +173,6 @@ public class UriTemplate implements Serializable { private final Pattern pattern; - private TemplateInfo(List vars, Pattern pattern) { this.variableNames = vars; this.pattern = pattern; @@ -187,7 +186,7 @@ public class UriTemplate implements Serializable { return this.pattern; } - private static TemplateInfo parse(String uriTemplate) { + public static TemplateInfo parse(String uriTemplate) { int level = 0; List variableNames = new ArrayList(); StringBuilder pattern = new StringBuilder(); @@ -216,8 +215,7 @@ public class UriTemplate implements Serializable { else { if (idx + 1 == variable.length()) { throw new IllegalArgumentException( - "No custom regular expression specified after ':' " + - "in \"" + variable + "\""); + "No custom regular expression specified after ':' in \"" + variable + "\""); } String regex = variable.substring(idx + 1, variable.length()); pattern.append('('); @@ -238,7 +236,7 @@ public class UriTemplate implements Serializable { } private static String quote(StringBuilder builder) { - return builder.length() != 0 ? Pattern.quote(builder.toString()) : ""; + return (builder.length() > 0 ? Pattern.quote(builder.toString()) : ""); } } diff --git a/spring-web/src/test/java/org/springframework/web/client/AsyncRestTemplateIntegrationTests.java b/spring-web/src/test/java/org/springframework/web/client/AsyncRestTemplateIntegrationTests.java index f3aac5602c..2dd6c04778 100644 --- a/spring-web/src/test/java/org/springframework/web/client/AsyncRestTemplateIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/AsyncRestTemplateIntegrationTests.java @@ -119,7 +119,6 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa assertNull("Invalid content", entity.getBody()); } - @Test public void getNoContentTypeHeader() throws Exception { Future> futureEntity = template.getForEntity(baseUrl + "/get/nocontenttype", byte[].class); @@ -127,7 +126,6 @@ public class AsyncRestTemplateIntegrationTests extends AbstractJettyServerTestCa assertArrayEquals("Invalid content", helloWorld.getBytes("UTF-8"), responseEntity.getBody()); } - @Test public void getNoContent() throws Exception { Future> responseFuture = template.getForEntity(baseUrl + "/status/nocontent", String.class); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java index ed714fcf4c..c8155e290e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ResourceServlet.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. @@ -86,7 +86,8 @@ import org.springframework.web.context.support.ServletContextResource; * @see #setDefaultUrl * @see #setAllowedResources * @see #setApplyLastModified - * @deprecated in favor of the ResourceHttpRequestHandler + * @deprecated as of Spring 4.3.5, in favor of + * {@link org.springframework.web.servlet.resource.ResourceHttpRequestHandler} */ @SuppressWarnings("serial") @Deprecated @@ -177,8 +178,8 @@ public class ResourceServlet extends HttpServletBean { } /** - * Return a PathMatcher to use for matching the "allowedResources" URL pattern. - * Default is AntPathMatcher. + * Return a {@link PathMatcher} to use for matching the "allowedResources" URL pattern. + *

The default is {@link AntPathMatcher}. * @see #setAllowedResources * @see org.springframework.util.AntPathMatcher */ @@ -193,9 +194,9 @@ public class ResourceServlet extends HttpServletBean { */ @Override protected final void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + throws ServletException, IOException { - // determine URL of resource to include + // Determine URL of resource to include... String resourceUrl = determineResourceUrl(request); if (resourceUrl != null) { @@ -222,7 +223,7 @@ public class ResourceServlet extends HttpServletBean { } } - // no resource URL specified -> try to include default URL. + // No resource URL specified -> try to include default URL. else if (!includeDefaultUrl(request, response)) { throw new ServletException("No target resource URL found for request"); } @@ -267,23 +268,23 @@ public class ResourceServlet extends HttpServletBean { * @throws IOException if thrown by the RequestDispatcher */ private void doInclude(HttpServletRequest request, HttpServletResponse response, String resourceUrl) - throws ServletException, IOException { + throws ServletException, IOException { if (this.contentType != null) { response.setContentType(this.contentType); } - String[] resourceUrls = - StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS); - for (int i = 0; i < resourceUrls.length; i++) { - // check whether URL matches allowed resources - if (this.allowedResources != null && !this.pathMatcher.match(this.allowedResources, resourceUrls[i])) { - throw new ServletException("Resource [" + resourceUrls[i] + + + String[] resourceUrls = StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS); + for (String url : resourceUrls) { + // Check whether URL matches allowed resources + if (this.allowedResources != null && !this.pathMatcher.match(this.allowedResources, url)) { + throw new ServletException("Resource [" + url + "] does not match allowed pattern [" + this.allowedResources + "]"); } if (logger.isDebugEnabled()) { - logger.debug("Including resource [" + resourceUrls[i] + "]"); + logger.debug("Including resource [" + url + "]"); } - RequestDispatcher rd = request.getRequestDispatcher(resourceUrls[i]); + RequestDispatcher rd = request.getRequestDispatcher(url); rd.include(request, response); } } @@ -311,8 +312,8 @@ public class ResourceServlet extends HttpServletBean { if (resourceUrl != null) { String[] resourceUrls = StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS); long latestTimestamp = -1; - for (int i = 0; i < resourceUrls.length; i++) { - long timestamp = getFileTimestamp(resourceUrls[i]); + for (String url : resourceUrls) { + long timestamp = getFileTimestamp(url); if (timestamp > latestTimestamp) { latestTimestamp = timestamp; } @@ -338,8 +339,10 @@ public class ResourceServlet extends HttpServletBean { return lastModifiedTime; } catch (IOException ex) { - logger.warn("Couldn't retrieve last-modified timestamp of [" + resource + - "] - using ResourceServlet startup time"); + if (logger.isWarnEnabled()) { + logger.warn("Couldn't retrieve last-modified timestamp of " + resource + + " - using ResourceServlet startup time"); + } return -1; } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketMessage.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketMessage.java index 5881ed0c34..fd5383d87e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketMessage.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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,11 +25,10 @@ package org.springframework.web.socket; public interface WebSocketMessage { /** - * Returns the message payload. This will never be {@code null}. + * Return the message payload (never {@code null}). */ T getPayload(); - /** * Return the number of bytes contained in the message. */ diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java index 515f55333f..5905bf5819 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java @@ -80,10 +80,10 @@ public abstract class AbstractSockJsSession implements SockJsSession { private static final Set disconnectedClientExceptions; static { - Set set = new HashSet(2); - set.add("ClientAbortException"); // Tomcat - set.add("EOFException"); // Tomcat - set.add("EofException"); // Jetty + Set set = new HashSet(4); + set.add("ClientAbortException"); // Tomcat + set.add("EOFException"); // Tomcat + set.add("EofException"); // Jetty // java.io.IOException "Broken pipe" on WildFly, Glassfish (already covered) disconnectedClientExceptions = Collections.unmodifiableSet(set); } @@ -208,7 +208,7 @@ public abstract class AbstractSockJsSession implements SockJsSession { writeFrameInternal(SockJsFrame.closeFrame(status.getCode(), status.getReason())); } catch (Throwable ex) { - logger.debug("Failure while send SockJS close frame", ex); + logger.debug("Failure while sending SockJS close frame", ex); } } updateLastActiveTime();