Skip to content

Commit 214d0d7

Browse files
committed
Polishing
1 parent 0f51ff5 commit 214d0d7

File tree

6 files changed

+60
-66
lines changed

6 files changed

+60
-66
lines changed

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResultInterceptor.java

Lines changed: 6 additions & 6 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-2017 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.
@@ -39,6 +39,7 @@ public CacheResultInterceptor(CacheErrorHandler errorHandler) {
3939
super(errorHandler);
4040
}
4141

42+
4243
@Override
4344
protected Object invoke(CacheOperationInvocationContext<CacheResultOperation> context,
4445
CacheOperationInvoker invoker) {
@@ -82,7 +83,6 @@ protected void checkForCachedException(Cache exceptionCache, Object cacheKey) {
8283
}
8384
}
8485

85-
8686
protected void cacheException(Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex) {
8787
if (exceptionCache == null) {
8888
return;
@@ -92,7 +92,6 @@ protected void cacheException(Cache exceptionCache, ExceptionTypeFilter filter,
9292
}
9393
}
9494

95-
9695
private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultOperation> context) {
9796
CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver();
9897
if (exceptionCacheResolver != null) {
@@ -101,18 +100,19 @@ private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultO
101100
return null;
102101
}
103102

103+
104104
/**
105105
* Rewrite the call stack of the specified {@code exception} so that it matches
106-
* the current call stack up-to (included) the specified method invocation.
106+
* the current call stack up to (included) the specified method invocation.
107107
* <p>Clone the specified exception. If the exception is not {@code serializable},
108108
* the original exception is returned. If no common ancestor can be found, returns
109109
* the original exception.
110110
* <p>Used to make sure that a cached exception has a valid invocation context.
111111
* @param exception the exception to merge with the current call stack
112112
* @param className the class name of the common ancestor
113113
* @param methodName the method name of the common ancestor
114-
* @return a clone exception with a rewritten call stack composed of the current
115-
* call stack up to (included) the common ancestor specified by the {@code className} and
114+
* @return a clone exception with a rewritten call stack composed of the current call
115+
* stack up to (included) the common ancestor specified by the {@code className} and
116116
* {@code methodName} arguments, followed by stack trace elements of the specified
117117
* {@code exception} after the common ancestor.
118118
*/

spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java

Lines changed: 19 additions & 25 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-2017 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.
@@ -49,9 +49,6 @@
4949
*/
5050
public class JCacheErrorHandlerTests {
5151

52-
@Rule
53-
public final ExpectedException thrown = ExpectedException.none();
54-
5552
private Cache cache;
5653

5754
private Cache errorCache;
@@ -60,20 +57,23 @@ public class JCacheErrorHandlerTests {
6057

6158
private SimpleService simpleService;
6259

60+
@Rule
61+
public final ExpectedException thrown = ExpectedException.none();
62+
63+
6364
@Before
6465
public void setup() {
65-
AnnotationConfigApplicationContext context =
66-
new AnnotationConfigApplicationContext(Config.class);
66+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
6767
this.cache = context.getBean("mockCache", Cache.class);
6868
this.errorCache = context.getBean("mockErrorCache", Cache.class);
6969
this.errorHandler = context.getBean(CacheErrorHandler.class);
7070
this.simpleService = context.getBean(SimpleService.class);
7171
}
7272

73+
7374
@Test
7475
public void getFail() {
75-
UnsupportedOperationException exception =
76-
new UnsupportedOperationException("Test exception on get");
76+
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
7777
Object key = SimpleKeyGenerator.generateKey(0L);
7878
willThrow(exception).given(this.cache).get(key);
7979

@@ -83,8 +83,7 @@ public void getFail() {
8383

8484
@Test
8585
public void getPutNewElementFail() {
86-
UnsupportedOperationException exception =
87-
new UnsupportedOperationException("Test exception on put");
86+
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
8887
Object key = SimpleKeyGenerator.generateKey(0L);
8988
given(this.cache.get(key)).willReturn(null);
9089
willThrow(exception).given(this.cache).put(key, 0L);
@@ -95,27 +94,24 @@ public void getPutNewElementFail() {
9594

9695
@Test
9796
public void getFailPutExceptionFail() {
98-
UnsupportedOperationException exceptionOnPut =
99-
new UnsupportedOperationException("Test exception on put");
97+
UnsupportedOperationException exceptionOnPut = new UnsupportedOperationException("Test exception on put");
10098
Object key = SimpleKeyGenerator.generateKey(0L);
10199
given(this.cache.get(key)).willReturn(null);
102-
willThrow(exceptionOnPut).given(this.errorCache).put(key,
103-
SimpleService.TEST_EXCEPTION);
100+
willThrow(exceptionOnPut).given(this.errorCache).put(key, SimpleService.TEST_EXCEPTION);
104101

105102
try {
106103
this.simpleService.getFail(0L);
107104
}
108105
catch (IllegalStateException ex) {
109106
assertEquals("Test exception", ex.getMessage());
110107
}
111-
verify(this.errorHandler).handleCachePutError(exceptionOnPut,
112-
this.errorCache, key, SimpleService.TEST_EXCEPTION);
108+
verify(this.errorHandler).handleCachePutError(
109+
exceptionOnPut, this.errorCache, key, SimpleService.TEST_EXCEPTION);
113110
}
114111

115112
@Test
116113
public void putFail() {
117-
UnsupportedOperationException exception =
118-
new UnsupportedOperationException("Test exception on put");
114+
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
119115
Object key = SimpleKeyGenerator.generateKey(0L);
120116
willThrow(exception).given(this.cache).put(key, 234L);
121117

@@ -125,8 +121,7 @@ public void putFail() {
125121

126122
@Test
127123
public void evictFail() {
128-
UnsupportedOperationException exception =
129-
new UnsupportedOperationException("Test exception on evict");
124+
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
130125
Object key = SimpleKeyGenerator.generateKey(0L);
131126
willThrow(exception).given(this.cache).evict(key);
132127

@@ -136,8 +131,7 @@ public void evictFail() {
136131

137132
@Test
138133
public void clearFail() {
139-
UnsupportedOperationException exception =
140-
new UnsupportedOperationException("Test exception on evict");
134+
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
141135
willThrow(exception).given(this.cache).clear();
142136

143137
this.simpleService.clear();
@@ -181,14 +175,13 @@ public Cache mockErrorCache() {
181175
given(cache.getName()).willReturn("error");
182176
return cache;
183177
}
184-
185178
}
186179

180+
187181
@CacheDefaults(cacheName = "test")
188182
public static class SimpleService {
189183

190-
private static final IllegalStateException TEST_EXCEPTION =
191-
new IllegalStateException("Test exception");
184+
private static final IllegalStateException TEST_EXCEPTION = new IllegalStateException("Test exception");
192185

193186
private AtomicLong counter = new AtomicLong();
194187

@@ -214,4 +207,5 @@ public void evict(long id) {
214207
public void clear() {
215208
}
216209
}
210+
217211
}

spring-expression/src/main/java/org/springframework/expression/spel/ast/Elvis.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -35,7 +35,7 @@
3535
public class Elvis extends SpelNodeImpl {
3636

3737
public Elvis(int pos, SpelNodeImpl... args) {
38-
super(pos,args);
38+
super(pos, args);
3939
}
4040

4141

@@ -88,7 +88,7 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
8888
mv.visitLdcInsn("");
8989
mv.visitInsn(SWAP);
9090
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false);
91-
mv.visitJumpInsn(IFEQ, endOfIf); // If not empty, drop through to elseTarget
91+
mv.visitJumpInsn(IFEQ, endOfIf); // if not empty, drop through to elseTarget
9292
mv.visitLabel(elseTarget);
9393
mv.visitInsn(POP);
9494
this.children[1].generateCode(mv, cf);

spring-expression/src/main/java/org/springframework/expression/spel/ast/Ternary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -35,7 +35,7 @@
3535
public class Ternary extends SpelNodeImpl {
3636

3737
public Ternary(int pos, SpelNodeImpl... args) {
38-
super(pos,args);
38+
super(pos, args);
3939
}
4040

4141

spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -4787,30 +4787,6 @@ public void ternaryOperator_SPR15192() {
47874787
assertIsCompiled(exp);
47884788
}
47894789

4790-
private void assertIsCompiled(Expression ex) {
4791-
try {
4792-
Field f = SpelExpression.class.getDeclaredField("compiledAst");
4793-
f.setAccessible(true);
4794-
Object object = f.get(ex);
4795-
assertNotNull(object);
4796-
} catch (Exception e) {
4797-
fail(e.toString());
4798-
}
4799-
}
4800-
4801-
public static class Foo {
4802-
4803-
public String bar() {
4804-
return "BAR";
4805-
}
4806-
4807-
public String bar(String arg) {
4808-
return arg.toUpperCase();
4809-
}
4810-
4811-
}
4812-
4813-
48144790

48154791
// helper methods
48164792

@@ -4871,6 +4847,20 @@ private void assertGetValueFail(Expression expression) {
48714847
}
48724848
}
48734849

4850+
private void assertIsCompiled(Expression expression) {
4851+
try {
4852+
Field field = SpelExpression.class.getDeclaredField("compiledAst");
4853+
field.setAccessible(true);
4854+
Object object = field.get(expression);
4855+
assertNotNull(object);
4856+
}
4857+
catch (Exception ex) {
4858+
fail(ex.toString());
4859+
}
4860+
}
4861+
4862+
4863+
// nested types
48744864

48754865
public interface Message<T> {
48764866

@@ -4987,7 +4977,7 @@ public void generateCode(String propertyName, MethodVisitor mv,CodeFlow cf) {
49874977
try {
49884978
method = Payload2.class.getDeclaredMethod("getField", String.class);
49894979
}
4990-
catch (Exception e) {
4980+
catch (Exception ex) {
49914981
}
49924982
}
49934983
String descriptor = cf.lastDescriptor();
@@ -5845,4 +5835,16 @@ public Map<String, String> getData() {
58455835
}
58465836
}
58475837

5838+
5839+
public static class Foo {
5840+
5841+
public String bar() {
5842+
return "BAR";
5843+
}
5844+
5845+
public String bar(String arg) {
5846+
return arg.toUpperCase();
5847+
}
5848+
}
5849+
58485850
}

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
105105

106106
@Override
107107
protected ListenableFuture<ClientHttpResponse> executeInternal(final HttpHeaders headers) throws IOException {
108-
final SettableListenableFuture<ClientHttpResponse> responseFuture =
109-
new SettableListenableFuture<>();
108+
final SettableListenableFuture<ClientHttpResponse> responseFuture = new SettableListenableFuture<>();
110109

111110
ChannelFutureListener connectionListener = new ChannelFutureListener() {
112111
@Override
@@ -141,8 +140,7 @@ private FullHttpRequest createFullHttpRequest(HttpHeaders headers) {
141140
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
142141
nettyRequest.headers().add(entry.getKey(), entry.getValue());
143142
}
144-
if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH)
145-
&& this.body.buffer().readableBytes() > 0) {
143+
if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) {
146144
nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes());
147145
}
148146

0 commit comments

Comments
 (0)