Browse Source

Polishing

pull/26383/head
Juergen Hoeller 6 years ago
parent
commit
ebd2ec57fc
  1. 16
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
  2. 3
      spring-context/src/main/java/org/springframework/context/annotation/DeferredImportSelector.java
  3. 3
      spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java
  4. 5
      spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java
  5. 8
      spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DatabasePopulatorUtils.java
  6. 10
      spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java
  7. 12
      spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java
  8. 16
      spring-web/src/main/java/org/springframework/http/codec/json/Jackson2Tokenizer.java
  9. 3
      spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -748,8 +748,7 @@ class ConfigurationClassParser { @@ -748,8 +748,7 @@ class ConfigurationClassParser {
* @param importSelector the selector to handle
*/
public void handle(ConfigurationClass configClass, DeferredImportSelector importSelector) {
DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder(
configClass, importSelector);
DeferredImportSelectorHolder holder = new DeferredImportSelectorHolder(configClass, importSelector);
if (this.deferredImportSelectors == null) {
DeferredImportSelectorGroupingHandler handler = new DeferredImportSelectorGroupingHandler();
handler.register(holder);
@ -775,7 +774,6 @@ class ConfigurationClassParser { @@ -775,7 +774,6 @@ class ConfigurationClassParser {
this.deferredImportSelectors = new ArrayList<>();
}
}
}
@ -786,8 +784,7 @@ class ConfigurationClassParser { @@ -786,8 +784,7 @@ class ConfigurationClassParser {
private final Map<AnnotationMetadata, ConfigurationClass> configurationClasses = new HashMap<>();
public void register(DeferredImportSelectorHolder deferredImport) {
Class<? extends Group> group = deferredImport.getImportSelector()
.getImportGroup();
Class<? extends Group> group = deferredImport.getImportSelector().getImportGroup();
DeferredImportSelectorGrouping grouping = this.groupings.computeIfAbsent(
(group != null ? group : deferredImport),
key -> new DeferredImportSelectorGrouping(createGroup(group)));
@ -799,8 +796,7 @@ class ConfigurationClassParser { @@ -799,8 +796,7 @@ class ConfigurationClassParser {
public void processGroupImports() {
for (DeferredImportSelectorGrouping grouping : this.groupings.values()) {
grouping.getImports().forEach(entry -> {
ConfigurationClass configurationClass = this.configurationClasses.get(
entry.getMetadata());
ConfigurationClass configurationClass = this.configurationClasses.get(entry.getMetadata());
try {
processImports(configurationClass, asSourceClass(configurationClass),
asSourceClasses(entry.getImportClassName()), false);
@ -818,8 +814,7 @@ class ConfigurationClassParser { @@ -818,8 +814,7 @@ class ConfigurationClassParser {
}
private Group createGroup(@Nullable Class<? extends Group> type) {
Class<? extends Group> effectiveType = (type != null ? type
: DefaultDeferredImportSelectorGroup.class);
Class<? extends Group> effectiveType = (type != null ? type : DefaultDeferredImportSelectorGroup.class);
Group group = BeanUtils.instantiateClass(effectiveType);
ParserStrategyUtils.invokeAwareMethods(group,
ConfigurationClassParser.this.environment,
@ -827,7 +822,6 @@ class ConfigurationClassParser { @@ -827,7 +822,6 @@ class ConfigurationClassParser {
ConfigurationClassParser.this.registry);
return group;
}
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -51,6 +51,7 @@ public interface DeferredImportSelector extends ImportSelector { @@ -51,6 +51,7 @@ public interface DeferredImportSelector extends ImportSelector {
/**
* Interface used to group results from different import selectors.
* @since 5.0
*/
interface Group {

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -50,6 +50,7 @@ public interface ImportSelector { @@ -50,6 +50,7 @@ public interface ImportSelector {
/**
* Select and return the names of which class(es) should be imported based on
* the {@link AnnotationMetadata} of the importing @{@link Configuration} class.
* @return the class names, or an empty array if none
*/
String[] selectImports(AnnotationMetadata importingClassMetadata);

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -530,9 +530,10 @@ public class ImportSelectorTests { @@ -530,9 +530,10 @@ public class ImportSelectorTests {
static Map<String, List<String>> allImports() {
return TestImportGroup.imports.entrySet()
.stream()
.collect(Collectors.toMap((entry) -> entry.getKey().getClassName(),
.collect(Collectors.toMap(entry -> entry.getKey().getClassName(),
Map.Entry::getValue));
}
private final List<Entry> instanceImports = new ArrayList<>();
@Override

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -52,10 +52,10 @@ public abstract class DatabasePopulatorUtils { @@ -52,10 +52,10 @@ public abstract class DatabasePopulatorUtils {
DataSourceUtils.releaseConnection(connection, dataSource);
}
}
catch (ScriptException ex) {
throw ex;
}
catch (Throwable ex) {
if (ex instanceof ScriptException) {
throw (ScriptException) ex;
}
throw new UncategorizedScriptException("Failed to execute database script", ex);
}
}

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

@ -116,7 +116,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple @@ -116,7 +116,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
if (elementType != null && BigDecimal.class.equals(elementType.getType())) {
if (BigDecimal.class.equals(elementType.getType())) {
forceUseOfBigDecimal = true;
}
@ -130,9 +130,10 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple @@ -130,9 +130,10 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
boolean forceUseOfBigDecimal = getObjectMapper().isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
if (elementType != null && BigDecimal.class.equals(elementType.getType())) {
if (BigDecimal.class.equals(elementType.getType())) {
forceUseOfBigDecimal = true;
}
Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(Flux.from(input), this.jsonFactory, getObjectMapper(),
false, forceUseOfBigDecimal, getMaxInMemorySize());
return decodeInternal(tokens, elementType, mimeType, hints).singleOrEmpty();
@ -177,7 +178,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple @@ -177,7 +178,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
}
// HttpMessageDecoder...
// HttpMessageDecoder
@Override
public Map<String, Object> getDecodeHints(ResolvableType actualType, ResolvableType elementType,
@ -191,7 +192,8 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple @@ -191,7 +192,8 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple
return getMimeTypes();
}
// Jackson2CodecSupport ...
// Jackson2CodecSupport
@Override
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {

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

@ -170,8 +170,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple @@ -170,8 +170,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
}
catch (IOException ex) {
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder",
ex);
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder", ex);
}
byte[] bytes = byteBuilder.toByteArray();
@ -197,8 +196,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple @@ -197,8 +196,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
throw new EncodingException("JSON encoding error: " + ex.getOriginalMessage(), ex);
}
catch (IOException ex) {
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder",
ex);
throw new IllegalStateException("Unexpected I/O error while writing to byte array builder", ex);
}
byte[] bytes = byteArrayBuilder.toByteArray();
@ -233,6 +231,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple @@ -233,6 +231,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
private ObjectWriter createObjectWriter(ResolvableType valueType, @Nullable MimeType mimeType,
@Nullable Map<String, Object> hints) {
JavaType javaType = getJavaType(valueType.getType(), null);
Class<?> jsonView = (hints != null ? (Class<?>) hints.get(Jackson2CodecSupport.JSON_VIEW_HINT) : null);
ObjectWriter writer = (jsonView != null ?
@ -280,7 +279,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple @@ -280,7 +279,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
}
// HttpMessageEncoder...
// HttpMessageEncoder
@Override
public List<MimeType> getEncodableMimeTypes() {
@ -299,7 +298,8 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple @@ -299,7 +298,8 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
return (actualType != null ? getHints(actualType) : Hints.none());
}
// Jackson2CodecSupport ...
// Jackson2CodecSupport
@Override
protected <A extends Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType) {

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

@ -36,7 +36,6 @@ import org.springframework.core.codec.DecodingException; @@ -36,7 +36,6 @@ import org.springframework.core.codec.DecodingException;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferLimitException;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
/**
* {@link Function} to transform a JSON stream of arbitrary size, byte array
@ -66,7 +65,6 @@ final class Jackson2Tokenizer { @@ -66,7 +65,6 @@ final class Jackson2Tokenizer {
private int byteCount;
@Nullable // yet initialized by calling createToken() in the constructor
private TokenBuffer tokenBuffer;
@ -84,7 +82,7 @@ final class Jackson2Tokenizer { @@ -84,7 +82,7 @@ final class Jackson2Tokenizer {
this.forceUseOfBigDecimal = forceUseOfBigDecimal;
this.inputFeeder = (ByteArrayFeeder) this.parser.getNonBlockingInputFeeder();
this.maxInMemorySize = maxInMemorySize;
createToken();
this.tokenBuffer = createToken();
}
@ -174,9 +172,8 @@ final class Jackson2Tokenizer { @@ -174,9 +172,8 @@ final class Jackson2Tokenizer {
if ((token.isStructEnd() || token.isScalarValue()) && this.objectDepth == 0 && this.arrayDepth == 0) {
result.add(this.tokenBuffer);
createToken();
this.tokenBuffer = createToken();
}
}
private void processTokenArray(JsonToken token, List<TokenBuffer> result) throws IOException {
@ -187,13 +184,14 @@ final class Jackson2Tokenizer { @@ -187,13 +184,14 @@ final class Jackson2Tokenizer {
if (this.objectDepth == 0 && (this.arrayDepth == 0 || this.arrayDepth == 1) &&
(token == JsonToken.END_OBJECT || token.isScalarValue())) {
result.add(this.tokenBuffer);
createToken();
this.tokenBuffer = createToken();
}
}
private void createToken() {
this.tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
this.tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
private TokenBuffer createToken() {
TokenBuffer tokenBuffer = new TokenBuffer(this.parser, this.deserializationContext);
tokenBuffer.forceUseOfBigDecimal(this.forceUseOfBigDecimal);
return tokenBuffer;
}
private boolean isTopLevelArrayToken(JsonToken token) {

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

@ -89,7 +89,7 @@ import org.springframework.web.util.UriTemplateHandler; @@ -89,7 +89,7 @@ import org.springframework.web.util.UriTemplateHandler;
*/
public class RestTemplate extends InterceptingHttpAccessor implements RestOperations {
private static boolean romePresent;
private static final boolean romePresent;
private static final boolean jaxb2Present;
@ -200,6 +200,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat @@ -200,6 +200,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
this.uriTemplateHandler = initUriTemplateHandler();
}
private static DefaultUriBuilderFactory initUriTemplateHandler() {
DefaultUriBuilderFactory uriFactory = new DefaultUriBuilderFactory();
uriFactory.setEncodingMode(EncodingMode.URI_COMPONENT); // for backwards compatibility..

Loading…
Cancel
Save