Skip to content

Commit d49ecab

Browse files
committed
Polishing
1 parent f7ace54 commit d49ecab

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -21,8 +21,8 @@
2121
*
2222
* <p>Does not provide a way to transmit checked exceptions but
2323
* provide a special exception that should be used to wrap any
24-
* exception that was thrown by the underlying invocation. Callers
25-
* are expected to handle this issue type specifically.
24+
* exception that was thrown by the underlying invocation.
25+
* Callers are expected to handle this issue type specifically.
2626
*
2727
* @author Stephane Nicoll
2828
* @since 4.1
@@ -38,11 +38,12 @@ public interface CacheOperationInvoker {
3838
*/
3939
Object invoke() throws ThrowableWrapper;
4040

41+
4142
/**
42-
* Wrap any exception thrown while invoking {@link #invoke()}
43+
* Wrap any exception thrown while invoking {@link #invoke()}.
4344
*/
4445
@SuppressWarnings("serial")
45-
public static class ThrowableWrapper extends RuntimeException {
46+
class ThrowableWrapper extends RuntimeException {
4647

4748
private final Throwable original;
4849

@@ -52,7 +53,7 @@ public ThrowableWrapper(Throwable original) {
5253
}
5354

5455
public Throwable getOriginal() {
55-
return original;
56+
return this.original;
5657
}
5758
}
5859

spring-context/src/test/java/org/springframework/cache/CacheReproTests.java

Lines changed: 10 additions & 8 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.
@@ -83,11 +83,11 @@ public void spr11592GetSimple() {
8383

8484
String key = "1";
8585
Object result = bean.getSimple("1");
86-
verify(cache, times(1)).get(key); // first call: cache miss
86+
verify(cache, times(1)).get(key); // first call: cache miss
8787

8888
Object cachedResult = bean.getSimple("1");
8989
assertSame(result, cachedResult);
90-
verify(cache, times(2)).get(key); // second call: cache hit
90+
verify(cache, times(2)).get(key); // second call: cache hit
9191

9292
context.close();
9393
}
@@ -100,11 +100,11 @@ public void spr11592GetNeverCache() {
100100

101101
String key = "1";
102102
Object result = bean.getNeverCache("1");
103-
verify(cache, times(0)).get(key); // no cache hit at all, caching disabled
103+
verify(cache, times(0)).get(key); // no cache hit at all, caching disabled
104104

105105
Object cachedResult = bean.getNeverCache("1");
106106
assertNotSame(result, cachedResult);
107-
verify(cache, times(0)).get(key); // caching disabled
107+
verify(cache, times(0)).get(key); // caching disabled
108108

109109
context.close();
110110
}
@@ -114,8 +114,9 @@ public void spr13081ConfigNoCacheNameIsRequired() {
114114
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr13081Config.class);
115115
MyCacheResolver cacheResolver = context.getBean(MyCacheResolver.class);
116116
Spr13081Service bean = context.getBean(Spr13081Service.class);
117+
117118
assertNull(cacheResolver.getCache("foo").get("foo"));
118-
Object result = bean.getSimple("foo"); // cache name = id
119+
Object result = bean.getSimple("foo"); // cache name = id
119120
assertEquals(result, cacheResolver.getCache("foo").get("foo").get());
120121
}
121122

@@ -124,7 +125,6 @@ public void spr13081ConfigFailIfCacheResolverReturnsNullCacheName() {
124125
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr13081Config.class);
125126
Spr13081Service bean = context.getBean(Spr13081Service.class);
126127

127-
128128
thrown.expect(IllegalStateException.class);
129129
thrown.expectMessage(MyCacheResolver.class.getName());
130130
bean.getSimple(null);
@@ -245,6 +245,7 @@ public Object getNeverCache(String key) {
245245
}
246246
}
247247

248+
248249
@Configuration
249250
@EnableCaching
250251
public static class Spr13081Config extends CachingConfigurerSupport {
@@ -259,9 +260,9 @@ public CacheResolver cacheResolver() {
259260
public Spr13081Service service() {
260261
return new Spr13081Service();
261262
}
262-
263263
}
264264

265+
265266
public static class MyCacheResolver extends AbstractCacheResolver {
266267

267268
public MyCacheResolver() {
@@ -282,6 +283,7 @@ public Cache getCache(String name) {
282283
}
283284
}
284285

286+
285287
public static class Spr13081Service {
286288

287289
@Cacheable

spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

Lines changed: 12 additions & 9 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.
@@ -265,7 +265,8 @@ public static Object invokeJdbcMethod(Method method, Object target, Object... ar
265265
* checked exception is expected to be thrown by the target method.
266266
* <p>Throws the underlying RuntimeException or Error in case of an
267267
* InvocationTargetException with such a root cause. Throws an
268-
* IllegalStateException with an appropriate message else.
268+
* IllegalStateException with an appropriate message or
269+
* UndeclaredThrowableException otherwise.
269270
* @param ex the reflection exception to handle
270271
*/
271272
public static void handleReflectionException(Exception ex) {
@@ -288,7 +289,7 @@ public static void handleReflectionException(Exception ex) {
288289
* Handle the given invocation target exception. Should only be called if no
289290
* checked exception is expected to be thrown by the target method.
290291
* <p>Throws the underlying RuntimeException or Error in case of such a root
291-
* cause. Throws an IllegalStateException else.
292+
* cause. Throws an UndeclaredThrowableException otherwise.
292293
* @param ex the invocation target exception to handle
293294
*/
294295
public static void handleInvocationTargetException(InvocationTargetException ex) {
@@ -300,8 +301,9 @@ public static void handleInvocationTargetException(InvocationTargetException ex)
300301
* <em>target exception</em> of an {@link InvocationTargetException}.
301302
* Should only be called if no checked exception is expected to be thrown
302303
* by the target method.
303-
* <p>Rethrows the underlying exception cast to an {@link RuntimeException} or
304-
* {@link Error} if appropriate; otherwise, throws an {@link IllegalStateException}.
304+
* <p>Rethrows the underlying exception cast to a {@link RuntimeException} or
305+
* {@link Error} if appropriate; otherwise, throws an
306+
* {@link UndeclaredThrowableException}.
305307
* @param ex the exception to rethrow
306308
* @throws RuntimeException the rethrown exception
307309
*/
@@ -321,7 +323,8 @@ public static void rethrowRuntimeException(Throwable ex) {
321323
* Should only be called if no checked exception is expected to be thrown
322324
* by the target method.
323325
* <p>Rethrows the underlying exception cast to an {@link Exception} or
324-
* {@link Error} if appropriate; otherwise, throws an {@link IllegalStateException}.
326+
* {@link Error} if appropriate; otherwise, throws an
327+
* {@link UndeclaredThrowableException}.
325328
* @param ex the exception to rethrow
326329
* @throws Exception the rethrown exception (in case of a checked exception)
327330
*/
@@ -804,7 +807,7 @@ public interface FieldFilter {
804807
/**
805808
* Pre-built FieldFilter that matches all non-static, non-final fields.
806809
*/
807-
public static FieldFilter COPYABLE_FIELDS = new FieldFilter() {
810+
public static final FieldFilter COPYABLE_FIELDS = new FieldFilter() {
808811

809812
@Override
810813
public boolean matches(Field field) {
@@ -816,7 +819,7 @@ public boolean matches(Field field) {
816819
/**
817820
* Pre-built MethodFilter that matches all non-bridge methods.
818821
*/
819-
public static MethodFilter NON_BRIDGED_METHODS = new MethodFilter() {
822+
public static final MethodFilter NON_BRIDGED_METHODS = new MethodFilter() {
820823

821824
@Override
822825
public boolean matches(Method method) {
@@ -829,7 +832,7 @@ public boolean matches(Method method) {
829832
* Pre-built MethodFilter that matches all non-bridge methods
830833
* which are not declared on {@code java.lang.Object}.
831834
*/
832-
public static MethodFilter USER_DECLARED_METHODS = new MethodFilter() {
835+
public static final MethodFilter USER_DECLARED_METHODS = new MethodFilter() {
833836

834837
@Override
835838
public boolean matches(Method method) {

0 commit comments

Comments
 (0)