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 ecec4ffda9..6dd21c1d10 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 @@ -374,18 +374,15 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker for (CacheOperationContext context : cachePutContexts) { try { if (!context.isConditionPassing(ExpressionEvaluator.RESULT_UNAVAILABLE)) { - excluded.add(context); + excluded.add(context); } } catch (VariableNotAvailableException e) { - // Ignoring failure due to missing result, consider the cache put has - // to proceed + // Ignoring failure due to missing result, consider the cache put has to proceed } } - // check if all puts have been excluded by condition - return cachePutContexts.size() != excluded.size(); - - + // Check if all puts have been excluded by condition + return (cachePutContexts.size() != excluded.size()); } private void processCacheEvicts(Collection contexts, boolean beforeInvocation, Object result) { @@ -710,4 +707,5 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker return (this.cacheOperation.hashCode() * 31 + this.methodCacheKey.hashCode()); } } + } diff --git a/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java b/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java index 97fc7a5dc1..8f7f88a9c2 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java +++ b/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-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. @@ -27,7 +27,7 @@ import org.springframework.util.ObjectUtils; * * @author Costin Leau * @author Stephane Nicoll - * @since 4.2.0 + * @since 4.2 * @see CachedExpressionEvaluator */ public final class AnnotatedElementKey { @@ -36,12 +36,13 @@ public final class AnnotatedElementKey { private final Class targetClass; + /** * Create a new instance with the specified {@link AnnotatedElement} and * optional target {@link Class}. */ public AnnotatedElementKey(AnnotatedElement element, Class targetClass) { - Assert.notNull(element, "AnnotatedElement must be set."); + Assert.notNull(element, "AnnotatedElement must not be null"); this.element = element; this.targetClass = targetClass; } diff --git a/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java b/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java index 81d0c55dc8..4bb20b2894 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java +++ b/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.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,13 +28,14 @@ import org.springframework.util.ObjectUtils; * are defined on {@link java.lang.reflect.AnnotatedElement}. * * @author Stephane Nicoll - * @since 4.2.0 + * @since 4.2 * @see AnnotatedElementKey */ public abstract class CachedExpressionEvaluator { private final SpelExpressionParser parser; + /** * Create a new instance with the specified {@link SpelExpressionParser}. */ @@ -50,6 +51,7 @@ public abstract class CachedExpressionEvaluator { this(new SpelExpressionParser()); } + /** * Return the {@link SpelExpressionParser} to use. */ @@ -57,6 +59,7 @@ public abstract class CachedExpressionEvaluator { return this.parser; } + /** * Return the {@link Expression} for the specified SpEL value *

Parse the expression if it hasn't been already. @@ -66,6 +69,7 @@ public abstract class CachedExpressionEvaluator { */ protected Expression getExpression(Map cache, AnnotatedElementKey elementKey, String expression) { + ExpressionKey expressionKey = createKey(elementKey, expression); Expression expr = cache.get(expressionKey); if (expr == null) { @@ -79,6 +83,7 @@ public abstract class CachedExpressionEvaluator { return new ExpressionKey(elementKey, expression); } + protected static class ExpressionKey { private final AnnotatedElementKey key; @@ -105,7 +110,7 @@ public abstract class CachedExpressionEvaluator { @Override public int hashCode() { - return this.key.hashCode() * 29 + (this.expression != null ? this.expression.hashCode() : 0); + return this.key.hashCode() + (this.expression != null ? this.expression.hashCode() * 29 : 0); } } diff --git a/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java b/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java index d5c1e21245..b6d783b2d7 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java +++ b/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.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,8 +25,8 @@ import org.springframework.util.ObjectUtils; /** * A method-based {@link org.springframework.expression.EvaluationContext} that * provides explicit support for method-based invocations. - *

- * Expose the actual method arguments using the following aliases: + * + *

Expose the actual method arguments using the following aliases: *

    *
  1. pX where X is the index of the argument (p0 for the first argument)
  2. *
  3. aX where X is the index of the argument (a1 for the second argument)
  4. @@ -34,7 +34,7 @@ import org.springframework.util.ObjectUtils; *
* * @author Stephane Nicoll - * @since 4.2.0 + * @since 4.2 */ public class MethodBasedEvaluationContext extends StandardEvaluationContext { @@ -46,6 +46,7 @@ public class MethodBasedEvaluationContext extends StandardEvaluationContext { private boolean paramLoaded = false; + public MethodBasedEvaluationContext(Object rootObject, Method method, Object[] args, ParameterNameDiscoverer paramDiscoverer) { @@ -55,6 +56,7 @@ public class MethodBasedEvaluationContext extends StandardEvaluationContext { this.paramDiscoverer = paramDiscoverer; } + @Override public Object lookupVariable(String name) { Object variable = super.lookupVariable(name); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java index 6ce23f8d00..39377075f7 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.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. @@ -48,7 +48,7 @@ public class JsonPathResultMatchers { * @param args arguments to parameterize the {@code JsonPath} expression with, * using formatting specifiers defined in {@link String#format(String, Object...)} */ - protected JsonPathResultMatchers(String expression, Object ... args) { + protected JsonPathResultMatchers(String expression, Object... args) { this.jsonPathHelper = new JsonPathExpectationsHelper(expression, args); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java index 91cfe65e07..0be4cb9bc2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.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. @@ -71,14 +71,11 @@ import org.springframework.web.util.WebUtils; * * @author Rossen Stoyanchev * @since 3.2 - * * @see #handleException(Exception, WebRequest) * @see org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver */ public abstract class ResponseEntityExceptionHandler { - protected final Log logger = LogFactory.getLog(getClass()); - /** * Log category to use when no mapped handler is found for a request. * @see #pageNotFoundLogger @@ -86,11 +83,16 @@ public abstract class ResponseEntityExceptionHandler { public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound"; /** - * Additional logger to use when no mapped handler is found for a request. + * Specific logger to use when no mapped handler is found for a request. * @see #PAGE_NOT_FOUND_LOG_CATEGORY */ protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY); + /** + * Common logger for use in subclasses. + */ + protected final Log logger = LogFactory.getLog(getClass()); + /** * Provides handling for standard Spring MVC exceptions. @@ -115,9 +117,7 @@ public abstract class ResponseEntityExceptionHandler { NoHandlerFoundException.class }) public final ResponseEntity handleException(Exception ex, WebRequest request) { - HttpHeaders headers = new HttpHeaders(); - if (ex instanceof NoSuchRequestHandlingMethodException) { HttpStatus status = HttpStatus.NOT_FOUND; return handleNoSuchRequestHandlingMethod((NoSuchRequestHandlingMethodException) ex, headers, status, request); @@ -202,7 +202,6 @@ public abstract class ResponseEntityExceptionHandler { if (HttpStatus.INTERNAL_SERVER_ERROR.equals(status)) { request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, ex, WebRequest.SCOPE_REQUEST); } - return new ResponseEntity(body, headers, status); } @@ -242,7 +241,6 @@ public abstract class ResponseEntityExceptionHandler { if (!supportedMethods.isEmpty()) { headers.setAllow(supportedMethods); } - return handleExceptionInternal(ex, null, headers, status, request); } @@ -443,8 +441,8 @@ public abstract class ResponseEntityExceptionHandler { * @return a {@code ResponseEntity} instance * @since 4.0 */ - protected ResponseEntity handleNoHandlerFoundException(NoHandlerFoundException ex, HttpHeaders headers, - HttpStatus status, WebRequest request) { + protected ResponseEntity handleNoHandlerFoundException( + NoHandlerFoundException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java index 8d322fed4e..f531989375 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java @@ -187,17 +187,15 @@ public class ResourceHttpRequestHandler extends WebContentGenerator } /** - * Look for a {@link org.springframework.web.servlet.resource.PathResourceResolver} - * among the {@link #getResourceResolvers() resource resolvers} and configure - * its {@code "allowedLocations"} to match the value of the - * {@link #setLocations(java.util.List) locations} property unless the "allowed - * locations" of the {@code PathResourceResolver} is non-empty. + * Look for a {@code PathResourceResolver} among the configured resource + * resolvers and set its {@code allowedLocations} property (if empty) to + * match the {@link #setLocations locations} configured on this class. */ protected void initAllowedLocations() { if (CollectionUtils.isEmpty(this.locations)) { return; } - for (int i = getResourceResolvers().size()-1; i >= 0; i--) { + for (int i = getResourceResolvers().size() - 1; i >= 0; i--) { if (getResourceResolvers().get(i) instanceof PathResourceResolver) { PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i); if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) { @@ -245,7 +243,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator // Apply cache settings, if any prepareResponse(response); - // Check the resource's media type + // Check the media type for the resource MediaType mediaType = getMediaType(resource); if (mediaType != null) { if (logger.isTraceEnabled()) {