Skip to content

Commit 94cb778

Browse files
committed
Polishing
1 parent 862d10c commit 94cb778

File tree

7 files changed

+37
-33
lines changed

7 files changed

+37
-33
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,4 +777,5 @@ public int hashCode() {
777777
return (this.cacheOperation.hashCode() * 31 + this.methodCacheKey.hashCode());
778778
}
779779
}
780+
780781
}

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class JsonPathResultMatchers {
4747

4848
private String prefix;
4949

50+
5051
/**
5152
* Protected constructor.
5253
* <p>Use {@link MockMvcResultMatchers#jsonPath(String, Object...)} or
@@ -65,7 +66,7 @@ protected JsonPathResultMatchers(String expression, Object... args) {
6566
* <p>Use this method if the JSON payloads are prefixed to avoid
6667
* Cross Site Script Inclusion (XSSI) attacks.
6768
* @param prefix the string prefix prepended to the actual JSON payload
68-
* @since 4.3.0
69+
* @since 4.3
6970
*/
7071
public JsonPathResultMatchers prefix(String prefix) {
7172
this.prefix = prefix;
@@ -252,14 +253,14 @@ private String getContent(MvcResult result) throws UnsupportedEncodingException
252253
String content = result.getResponse().getContentAsString();
253254
if (StringUtils.hasLength(this.prefix)) {
254255
try {
255-
String reason = String.format("Expected a JSON payload prefixed with \"%s\" but found: %s", this.prefix,
256-
StringUtils.quote(content.substring(0, this.prefix.length())));
256+
String reason = String.format("Expected a JSON payload prefixed with \"%s\" but found: %s",
257+
this.prefix, StringUtils.quote(content.substring(0, this.prefix.length())));
257258
MatcherAssert.assertThat(reason, content, StringStartsWith.startsWith(this.prefix));
258259
return content.substring(this.prefix.length());
259260
}
260261
catch (StringIndexOutOfBoundsException oobe) {
261-
String message = "JSON prefix \"" + this.prefix + "\" not found, exception: ";
262-
throw new AssertionError(message + oobe.getMessage());
262+
throw new AssertionError(
263+
"JSON prefix \"" + this.prefix + "\" not found, exception: " + oobe.getMessage());
263264
}
264265
}
265266
else {

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public List<ResourceTransformer> getResourceTransformers() {
162162
/**
163163
* Configure the {@link ResourceHttpMessageConverter} to use.
164164
* <p>By default a {@link ResourceHttpMessageConverter} will be configured.
165-
* @since 4.3.0
165+
* @since 4.3
166166
*/
167167
public void setResourceHttpMessageConverter(ResourceHttpMessageConverter resourceHttpMessageConverter) {
168168
this.resourceHttpMessageConverter = resourceHttpMessageConverter;
@@ -172,7 +172,6 @@ public ResourceHttpMessageConverter getResourceHttpMessageConverter() {
172172
return this.resourceHttpMessageConverter;
173173
}
174174

175-
176175
/**
177176
* Configure a {@code ContentNegotiationManager} to determine the media types
178177
* for resources being served. If the manager contains a path
@@ -185,7 +184,7 @@ public ResourceHttpMessageConverter getResourceHttpMessageConverter() {
185184
* settings is used to create the manager. See the Javadoc of
186185
* {@code ContentNegotiationManagerFactoryBean} for details
187186
* @param contentNegotiationManager the manager to use
188-
* @since 4.3.0
187+
* @since 4.3
189188
*/
190189
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager) {
191190
this.contentNegotiationManager = contentNegotiationManager;
@@ -335,10 +334,7 @@ public void handleRequest(HttpServletRequest request, HttpServletResponse respon
335334
this.resourceHttpMessageConverter.write(rangeResource, mediaType, outputMessage);
336335
}
337336
catch (IllegalArgumentException ex) {
338-
Long contentLength = resource.contentLength();
339-
if (contentLength != null) {
340-
response.addHeader("Content-Range", "bytes */" + resource.contentLength());
341-
}
337+
response.addHeader("Content-Range", "bytes */" + resource.contentLength());
342338
response.sendError(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
343339
}
344340
}
@@ -468,7 +464,6 @@ protected boolean isInvalidPath(String path) {
468464
*/
469465
@SuppressWarnings("deprecation")
470466
protected MediaType getMediaType(HttpServletRequest request, Resource resource) {
471-
472467
// For backwards compatibility
473468
MediaType mediaType = getMediaType(resource);
474469
if (mediaType != null) {
@@ -535,6 +530,7 @@ protected void setHeaders(HttpServletResponse response, Resource resource, Media
535530
response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes");
536531
}
537532

533+
538534
@Override
539535
public String toString() {
540536
return "ResourceHttpRequestHandler [locations=" + getLocations() + ", resolvers=" + getResourceResolvers() + "]";

0 commit comments

Comments
 (0)