Skip to content

Commit ebd2ec5

Browse files
committed
Polishing
1 parent f536819 commit ebd2ec5

File tree

9 files changed

+37
-39
lines changed

9 files changed

+37
-39
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -748,8 +748,7 @@ private class DeferredImportSelectorHandler {
748748
* @param importSelector the selector to handle
749749
*/
750750
public void handle(ConfigurationClass configClass, DeferredImportSelector importSelector) {
751-
DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder(
752-
configClass, importSelector);
751+
DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder(configClass, importSelector);
753752
if (this.deferredImportSelectors == null) {
754753
DeferredImportSelectorGroupingHandler handler = new DeferredImportSelectorGroupingHandler();
755754
handler.register(holder);
@@ -775,7 +774,6 @@ public void process() {
775774
this.deferredImportSelectors = new ArrayList<>();
776775
}
777776
}
778-
779777
}
780778

781779

@@ -786,8 +784,7 @@ private class DeferredImportSelectorGroupingHandler {
786784
private final Map<AnnotationMetadata, ConfigurationClass> configurationClasses = new HashMap<>();
787785

788786
public void register(DeferredImportSelectorHolder deferredImport) {
789-
Class<? extends Group> group = deferredImport.getImportSelector()
790-
.getImportGroup();
787+
Class<? extends Group> group = deferredImport.getImportSelector().getImportGroup();
791788
DeferredImportSelectorGrouping grouping = this.groupings.computeIfAbsent(
792789
(group != null ? group : deferredImport),
793790
key -> new DeferredImportSelectorGrouping(createGroup(group)));
@@ -799,8 +796,7 @@ public void register(DeferredImportSelectorHolder deferredImport) {
799796
public void processGroupImports() {
800797
for (DeferredImportSelectorGrouping grouping : this.groupings.values()) {
801798
grouping.getImports().forEach(entry -> {
802-
ConfigurationClass configurationClass = this.configurationClasses.get(
803-
entry.getMetadata());
799+
ConfigurationClass configurationClass = this.configurationClasses.get(entry.getMetadata());
804800
try {
805801
processImports(configurationClass, asSourceClass(configurationClass),
806802
asSourceClasses(entry.getImportClassName()), false);
@@ -818,16 +814,14 @@ public void processGroupImports() {
818814
}
819815

820816
private Group createGroup(@Nullable Class<? extends Group> type) {
821-
Class<? extends Group> effectiveType = (type != null ? type
822-
: DefaultDeferredImportSelectorGroup.class);
817+
Class<? extends Group> effectiveType = (type != null ? type : DefaultDeferredImportSelectorGroup.class);
823818
Group group = BeanUtils.instantiateClass(effectiveType);
824819
ParserStrategyUtils.invokeAwareMethods(group,
825820
ConfigurationClassParser.this.environment,
826821
ConfigurationClassParser.this.resourceLoader,
827822
ConfigurationClassParser.this.registry);
828823
return group;
829824
}
830-
831825
}
832826

833827

spring-context/src/main/java/org/springframework/context/annotation/DeferredImportSelector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -51,6 +51,7 @@ default Class<? extends Group> getImportGroup() {
5151

5252
/**
5353
* Interface used to group results from different import selectors.
54+
* @since 5.0
5455
*/
5556
interface Group {
5657

spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -50,6 +50,7 @@ public interface ImportSelector {
5050
/**
5151
* Select and return the names of which class(es) should be imported based on
5252
* the {@link AnnotationMetadata} of the importing @{@link Configuration} class.
53+
* @return the class names, or an empty array if none
5354
*/
5455
String[] selectImports(AnnotationMetadata importingClassMetadata);
5556

spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -530,9 +530,10 @@ static void cleanup() {
530530
static Map<String, List<String>> allImports() {
531531
return TestImportGroup.imports.entrySet()
532532
.stream()
533-
.collect(Collectors.toMap((entry) -> entry.getKey().getClassName(),
533+
.collect(Collectors.toMap(entry -> entry.getKey().getClassName(),
534534
Map.Entry::getValue));
535535
}
536+
536537
private final List<Entry> instanceImports = new ArrayList<>();
537538

538539
@Override

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -52,10 +52,10 @@ public static void execute(DatabasePopulator populator, DataSource dataSource) t
5252
DataSourceUtils.releaseConnection(connection, dataSource);
5353
}
5454
}
55+
catch (ScriptException ex) {
56+
throw ex;
57+
}
5558
catch (Throwable ex) {
56-
if (ex instanceof ScriptException) {
57-
throw (ScriptException) ex;
58-
}
5959
throw new UncategorizedScriptException("Failed to execute database script", ex);
6060
}
6161
}

spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public Flux<Object> decode(Publisher<DataBuffer> input, ResolvableType elementTy
116116
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
117117

118118
boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
119-
if (elementType != null && BigDecimal.class.equals(elementType.getType())) {
119+
if (BigDecimal.class.equals(elementType.getType())) {
120120
forceUseOfBigDecimal = true;
121121
}
122122

@@ -130,9 +130,10 @@ public Mono<Object> decodeToMono(Publisher<DataBuffer> input, ResolvableType ele
130130
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
131131

132132
boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
133-
if (elementType != null && BigDecimal.class.equals(elementType.getType())) {
133+
if (BigDecimal.class.equals(elementType.getType())) {
134134
forceUseOfBigDecimal = true;
135135
}
136+
136137
Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(Flux.from(input), this.jsonFactory, getObjectMapper(),
137138
false, forceUseOfBigDecimal, getMaxInMemorySize());
138139
return decodeInternal(tokens, elementType, mimeType, hints).singleOrEmpty();
@@ -177,7 +178,7 @@ private Flux<Object> decodeInternal(Flux<TokenBuffer> tokens, ResolvableType ele
177178
}
178179

179180

180-
// HttpMessageDecoder...
181+
// HttpMessageDecoder
181182

182183
@Override
183184
public Map<String, Object> getDecodeHints(ResolvableType actualType, ResolvableType elementType,
@@ -191,7 +192,8 @@ public List<MimeType> getDecodableMimeTypes() {
191192
return getMimeTypes();
192193
}
193194

194-
// Jackson2CodecSupport ...
195+
196+
// Jackson2CodecSupport
195197

196198
@Override
197199
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {

spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory,
170170
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
171171
}
172172
catch (IOException ex) {
173-
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder",
174-
ex);
173+
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder", ex);
175174
}
176175

177176
byte[] bytes = byteBuilder.toByteArray();
@@ -197,8 +196,7 @@ private DataBuffer encodeStreamingValue(Object value, DataBufferFactory bufferFa
197196
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
198197
}
199198
catch (IOException ex) {
200-
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder",
201-
ex);
199+
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder", ex);
202200
}
203201

204202
byte[] bytes = byteArrayBuilder.toByteArray();
@@ -233,6 +231,7 @@ private void logValue(@Nullable Map<String, Object> hints, Object value) {
233231

234232
private ObjectWriter createObjectWriter(ResolvableType valueType, @Nullable MimeType mimeType,
235233
@Nullable Map<String, Object> hints) {
234+
236235
JavaType javaType = getJavaType(valueType.getType(), null);
237236
Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null);
238237
ObjectWriter writer = (jsonView != null ?
@@ -280,7 +279,7 @@ protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType) {
280279
}
281280

282281

283-
// HttpMessageEncoder...
282+
// HttpMessageEncoder
284283

285284
@Override
286285
public List<MimeType> getEncodableMimeTypes() {
@@ -299,7 +298,8 @@ public Map<String, Object> getEncodeHints(@Nullable ResolvableType actualType, R
299298
return (actualType != null ? getHints(actualType) : Hints.none());
300299
}
301300

302-
// Jackson2CodecSupport ...
301+
302+
// Jackson2CodecSupport
303303

304304
@Override
305305
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {

spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.core.io.buffer.DataBuffer;
3737
import org.springframework.core.io.buffer.DataBufferLimitException;
3838
import org.springframework.core.io.buffer.DataBufferUtils;
39-
import org.springframework.lang.Nullable;
4039

4140
/**
4241
* {@link Function} to transform a JSON stream of arbitrary size, byte array
@@ -66,7 +65,6 @@ final class Jackson2Tokenizer {
6665

6766
private int byteCount;
6867

69-
@Nullable // yet initialized by calling createToken() in the constructor
7068
private TokenBuffer tokenBuffer;
7169

7270

@@ -84,7 +82,7 @@ private Jackson2Tokenizer(JsonParser parser, DeserializationContext deserializat
8482
this.forceUseOfBigDecimal = forceUseOfBigDecimal;
8583
this.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();
8684
this.maxInMemorySize = maxInMemorySize;
87-
createToken();
85+
this.tokenBuffer = createToken();
8886
}
8987

9088

@@ -174,9 +172,8 @@ private void processTokenNormal(JsonToken token, List<TokenBuffer> result) throw
174172

175173
if ((token.isStructEnd() || token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) {
176174
result.add(this.tokenBuffer);
177-
createToken();
175+
this.tokenBuffer = createToken();
178176
}
179-
180177
}
181178

182179
private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws IOException {
@@ -187,13 +184,14 @@ private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws
187184
if (this.objectDepth == 0 && (this.arrayDepth == 0 || this.arrayDepth == 1) &&
188185
(token == JsonToken.END_OBJECT || token.isScalarValue())) {
189186
result.add(this.tokenBuffer);
190-
createToken();
187+
this.tokenBuffer = createToken();
191188
}
192189
}
193190

194-
private void createToken() {
195-
this.tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
196-
this.tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
191+
private TokenBuffer createToken() {
192+
TokenBuffer tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
193+
tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
194+
return tokenBuffer;
197195
}
198196

199197
private boolean isTopLevelArrayToken(JsonToken token) {

spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
*/
9090
public class RestTemplate extends InterceptingHttpAccessor implements RestOperations {
9191

92-
private static boolean romePresent;
92+
private static final boolean romePresent;
9393

9494
private static final boolean jaxb2Present;
9595

@@ -200,6 +200,7 @@ public RestTemplate(List<HttpMessageConverter<?>> messageConverters) {
200200
this.uriTemplateHandler = initUriTemplateHandler();
201201
}
202202

203+
203204
private static DefaultUriBuilderFactory initUriTemplateHandler() {
204205
DefaultUriBuilderFactory uriFactory = new DefaultUriBuilderFactory();
205206
uriFactory.setEncodingMode(EncodingMode.URI_COMPONENT); // for backwards compatibility..

0 commit comments

Comments
 (0)