Skip to content

Commit 756301b

Browse files
committed
Polishing
(cherry picked from commit 94cb778)
1 parent ccaa504 commit 756301b

File tree

7 files changed

+39
-37
lines changed

7 files changed

+39
-37
lines changed

spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,15 @@ private boolean hasCachePut(CacheOperationContexts contexts) {
374374
for (CacheOperationContext context : cachePutContexts) {
375375
try {
376376
if (!context.isConditionPassing(ExpressionEvaluator.RESULT_UNAVAILABLE)) {
377-
excluded.add(context);
377+
excluded.add(context);
378378
}
379379
}
380380
catch (VariableNotAvailableException e) {
381-
// Ignoring failure due to missing result, consider the cache put has
382-
// to proceed
381+
// Ignoring failure due to missing result, consider the cache put has to proceed
383382
}
384383
}
385-
// check if all puts have been excluded by condition
386-
return cachePutContexts.size() != excluded.size();
387-
388-
384+
// Check if all puts have been excluded by condition
385+
return (cachePutContexts.size() != excluded.size());
389386
}
390387

391388
private void processCacheEvicts(Collection<CacheOperationContext> contexts, boolean beforeInvocation, Object result) {
@@ -710,4 +707,5 @@ public int hashCode() {
710707
return (this.cacheOperation.hashCode() * 31 + this.methodCacheKey.hashCode());
711708
}
712709
}
710+
713711
}

spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
*
2828
* @author Costin Leau
2929
* @author Stephane Nicoll
30-
* @since 4.2.0
30+
* @since 4.2
3131
* @see CachedExpressionEvaluator
3232
*/
3333
public final class AnnotatedElementKey {
@@ -36,12 +36,13 @@ public final class AnnotatedElementKey {
3636

3737
private final Class<?> targetClass;
3838

39+
3940
/**
4041
* Create a new instance with the specified {@link AnnotatedElement} and
4142
* optional target {@link Class}.
4243
*/
4344
public AnnotatedElementKey(AnnotatedElement element, Class<?> targetClass) {
44-
Assert.notNull(element, "AnnotatedElement must be set.");
45+
Assert.notNull(element, "AnnotatedElement must not be null");
4546
this.element = element;
4647
this.targetClass = targetClass;
4748
}

spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,13 +28,14 @@
2828
* are defined on {@link java.lang.reflect.AnnotatedElement}.
2929
*
3030
* @author Stephane Nicoll
31-
* @since 4.2.0
31+
* @since 4.2
3232
* @see AnnotatedElementKey
3333
*/
3434
public abstract class CachedExpressionEvaluator {
3535

3636
private final SpelExpressionParser parser;
3737

38+
3839
/**
3940
* Create a new instance with the specified {@link SpelExpressionParser}.
4041
*/
@@ -50,13 +51,15 @@ protected CachedExpressionEvaluator() {
5051
this(new SpelExpressionParser());
5152
}
5253

54+
5355
/**
5456
* Return the {@link SpelExpressionParser} to use.
5557
*/
5658
protected SpelExpressionParser getParser() {
5759
return this.parser;
5860
}
5961

62+
6063
/**
6164
* Return the {@link Expression} for the specified SpEL value
6265
* <p>Parse the expression if it hasn't been already.
@@ -66,6 +69,7 @@ protected SpelExpressionParser getParser() {
6669
*/
6770
protected Expression getExpression(Map<ExpressionKey, Expression> cache,
6871
AnnotatedElementKey elementKey, String expression) {
72+
6973
ExpressionKey expressionKey = createKey(elementKey, expression);
7074
Expression expr = cache.get(expressionKey);
7175
if (expr == null) {
@@ -79,6 +83,7 @@ private ExpressionKey createKey(AnnotatedElementKey elementKey, String expressio
7983
return new ExpressionKey(elementKey, expression);
8084
}
8185

86+
8287
protected static class ExpressionKey {
8388

8489
private final AnnotatedElementKey key;
@@ -105,7 +110,7 @@ public boolean equals(Object other) {
105110

106111
@Override
107112
public int hashCode() {
108-
return this.key.hashCode() * 29 + (this.expression != null ? this.expression.hashCode() : 0);
113+
return this.key.hashCode() + (this.expression != null ? this.expression.hashCode() * 29 : 0);
109114
}
110115
}
111116

spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,16 +25,16 @@
2525
/**
2626
* A method-based {@link org.springframework.expression.EvaluationContext} that
2727
* provides explicit support for method-based invocations.
28-
* <p>
29-
* Expose the actual method arguments using the following aliases:
28+
*
29+
* <p>Expose the actual method arguments using the following aliases:
3030
* <ol>
3131
* <li>pX where X is the index of the argument (p0 for the first argument)</li>
3232
* <li>aX where X is the index of the argument (a1 for the second argument)</li>
3333
* <li>the name of the parameter as discovered by a configurable {@link ParameterNameDiscoverer}</li>
3434
* </ol>
3535
*
3636
* @author Stephane Nicoll
37-
* @since 4.2.0
37+
* @since 4.2
3838
*/
3939
public class MethodBasedEvaluationContext extends StandardEvaluationContext {
4040

@@ -46,6 +46,7 @@ public class MethodBasedEvaluationContext extends StandardEvaluationContext {
4646

4747
private boolean paramLoaded = false;
4848

49+
4950
public MethodBasedEvaluationContext(Object rootObject, Method method, Object[] args,
5051
ParameterNameDiscoverer paramDiscoverer) {
5152

@@ -55,6 +56,7 @@ public MethodBasedEvaluationContext(Object rootObject, Method method, Object[] a
5556
this.paramDiscoverer = paramDiscoverer;
5657
}
5758

59+
5860
@Override
5961
public Object lookupVariable(String name) {
6062
Object variable = super.lookupVariable(name);

spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ public class JsonPathResultMatchers {
4848
* @param args arguments to parameterize the {@code JsonPath} expression with,
4949
* using formatting specifiers defined in {@link String#format(String, Object...)}
5050
*/
51-
protected JsonPathResultMatchers(String expression, Object ... args) {
51+
protected JsonPathResultMatchers(String expression, Object... args) {
5252
this.jsonPathHelper = new JsonPathExpectationsHelper(expression, args);
5353
}
5454

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -71,26 +71,28 @@
7171
*
7272
* @author Rossen Stoyanchev
7373
* @since 3.2
74-
*
7574
* @see #handleException(Exception, WebRequest)
7675
* @see org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
7776
*/
7877
public abstract class ResponseEntityExceptionHandler {
7978

80-
protected final Log logger = LogFactory.getLog(getClass());
81-
8279
/**
8380
* Log category to use when no mapped handler is found for a request.
8481
* @see #pageNotFoundLogger
8582
*/
8683
public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound";
8784

8885
/**
89-
* Additional logger to use when no mapped handler is found for a request.
86+
* Specific logger to use when no mapped handler is found for a request.
9087
* @see #PAGE_NOT_FOUND_LOG_CATEGORY
9188
*/
9289
protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY);
9390

91+
/**
92+
* Common logger for use in subclasses.
93+
*/
94+
protected final Log logger = LogFactory.getLog(getClass());
95+
9496

9597
/**
9698
* Provides handling for standard Spring MVC exceptions.
@@ -115,9 +117,7 @@ public abstract class ResponseEntityExceptionHandler {
115117
NoHandlerFoundException.class
116118
})
117119
public final ResponseEntity<Object> handleException(Exception ex, WebRequest request) {
118-
119120
HttpHeaders headers = new HttpHeaders();
120-
121121
if (ex instanceof NoSuchRequestHandlingMethodException) {
122122
HttpStatus status = HttpStatus.NOT_FOUND;
123123
return handleNoSuchRequestHandlingMethod((NoSuchRequestHandlingMethodException) ex, headers, status, request);
@@ -202,7 +202,6 @@ protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object bo
202202
if (HttpStatus.INTERNAL_SERVER_ERROR.equals(status)) {
203203
request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, ex, WebRequest.SCOPE_REQUEST);
204204
}
205-
206205
return new ResponseEntity<Object>(body, headers, status);
207206
}
208207

@@ -242,7 +241,6 @@ protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(HttpRequest
242241
if (!supportedMethods.isEmpty()) {
243242
headers.setAllow(supportedMethods);
244243
}
245-
246244
return handleExceptionInternal(ex, null, headers, status, request);
247245
}
248246

@@ -443,8 +441,8 @@ protected ResponseEntity<Object> handleBindException(BindException ex, HttpHeade
443441
* @return a {@code ResponseEntity} instance
444442
* @since 4.0
445443
*/
446-
protected ResponseEntity<Object> handleNoHandlerFoundException(NoHandlerFoundException ex, HttpHeaders headers,
447-
HttpStatus status, WebRequest request) {
444+
protected ResponseEntity<Object> handleNoHandlerFoundException(
445+
NoHandlerFoundException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
448446

449447
return handleExceptionInternal(ex, null, headers, status, request);
450448
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,15 @@ public void afterPropertiesSet() throws Exception {
187187
}
188188

189189
/**
190-
* Look for a {@link org.springframework.web.servlet.resource.PathResourceResolver}
191-
* among the {@link #getResourceResolvers() resource resolvers} and configure
192-
* its {@code "allowedLocations"} to match the value of the
193-
* {@link #setLocations(java.util.List) locations} property unless the "allowed
194-
* locations" of the {@code PathResourceResolver} is non-empty.
190+
* Look for a {@code PathResourceResolver} among the configured resource
191+
* resolvers and set its {@code allowedLocations} property (if empty) to
192+
* match the {@link #setLocations locations} configured on this class.
195193
*/
196194
protected void initAllowedLocations() {
197195
if (CollectionUtils.isEmpty(this.locations)) {
198196
return;
199197
}
200-
for (int i = getResourceResolvers().size()-1; i >= 0; i--) {
198+
for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
201199
if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
202200
PathResourceResolver pathResolver = (PathResourceResolver) getResourceResolvers().get(i);
203201
if (ObjectUtils.isEmpty(pathResolver.getAllowedLocations())) {
@@ -245,7 +243,7 @@ public void handleRequest(HttpServletRequest request, HttpServletResponse respon
245243
// Apply cache settings, if any
246244
prepareResponse(response);
247245

248-
// Check the resource's media type
246+
// Check the media type for the resource
249247
MediaType mediaType = getMediaType(resource);
250248
if (mediaType != null) {
251249
if (logger.isTraceEnabled()) {

0 commit comments

Comments
 (0)