Skip to content

Commit f4c0ceb

Browse files
committed
Merge branch '5.2.x'
# Conflicts: # build.gradle # spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslationInterceptor.java # spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java # spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java # spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java
2 parents 14839b1 + 692c5f2 commit f4c0ceb

File tree

9 files changed

+64
-28
lines changed

9 files changed

+64
-28
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) {
325325
this.allowBeanDefinitionOverriding = otherListableFactory.allowBeanDefinitionOverriding;
326326
this.allowEagerClassLoading = otherListableFactory.allowEagerClassLoading;
327327
this.dependencyComparator = otherListableFactory.dependencyComparator;
328-
// A clone of the AutowireCandidateResolver since it is potentially BeanFactoryAware...
328+
// A clone of the AutowireCandidateResolver since it is potentially BeanFactoryAware
329329
setAutowireCandidateResolver(otherListableFactory.getAutowireCandidateResolver().cloneIfNecessary());
330-
// Make resolvable dependencies (e.g. ResourceLoader) available here as well...
330+
// Make resolvable dependencies (e.g. ResourceLoader) available here as well
331331
this.resolvableDependencies.putAll(otherListableFactory.resolvableDependencies);
332332
}
333333
}
@@ -462,13 +462,15 @@ public void ifUnique(Consumer<T> dependencyConsumer) throws BeansException {
462462
}
463463
}
464464
}
465+
@SuppressWarnings("unchecked")
465466
@Override
466467
@SuppressWarnings("unchecked")
467468
public Stream<T> stream() {
468469
return Arrays.stream(getBeanNamesForTypedStream(requiredType, allowEagerInit))
469470
.map(name -> (T) getBean(name))
470471
.filter(bean -> !(bean instanceof NullBean));
471472
}
473+
@SuppressWarnings("unchecked")
472474
@Override
473475
@SuppressWarnings("unchecked")
474476
public Stream<T> orderedStream() {

spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java

Lines changed: 2 additions & 3 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.
@@ -55,8 +55,7 @@ public final boolean isAllowNullValues() {
5555
@Override
5656
@Nullable
5757
public ValueWrapper get(Object key) {
58-
Object value = lookup(key);
59-
return toValueWrapper(value);
58+
return toValueWrapper(lookup(key));
6059
}
6160

6261
@Override

spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java

Lines changed: 2 additions & 2 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.
@@ -52,7 +52,7 @@ public class FileUrlResource extends UrlResource implements WritableResource {
5252
/**
5353
* Create a new {@code FileUrlResource} based on the given URL object.
5454
* <p>Note that this does not enforce "file" as URL protocol. If a protocol
55-
* is known to be resolvable to a file,
55+
* is known to be resolvable to a file, it is acceptable for this purpose.
5656
* @param url a URL
5757
* @see ResourceUtils#isFileURL(URL)
5858
* @see #getFile()

spring-core/src/main/java/org/springframework/core/io/UrlResource.java

Lines changed: 23 additions & 10 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.
@@ -56,7 +56,8 @@ public class UrlResource extends AbstractFileResolvingResource {
5656
/**
5757
* Cleaned URL (with normalized path), used for comparisons.
5858
*/
59-
private final URL cleanedUrl;
59+
@Nullable
60+
private volatile URL cleanedUrl;
6061

6162

6263
/**
@@ -69,7 +70,6 @@ public UrlResource(URI uri) throws MalformedURLException {
6970
Assert.notNull(uri, "URI must not be null");
7071
this.uri = uri;
7172
this.url = uri.toURL();
72-
this.cleanedUrl = getCleanedUrl(this.url, uri.toString());
7373
}
7474

7575
/**
@@ -78,9 +78,8 @@ public UrlResource(URI uri) throws MalformedURLException {
7878
*/
7979
public UrlResource(URL url) {
8080
Assert.notNull(url, "URL must not be null");
81-
this.url = url;
82-
this.cleanedUrl = getCleanedUrl(this.url, url.toString());
8381
this.uri = null;
82+
this.url = url;
8483
}
8584

8685
/**
@@ -127,7 +126,6 @@ public UrlResource(String protocol, String location, @Nullable String fragment)
127126
try {
128127
this.uri = new URI(protocol, location, fragment);
129128
this.url = this.uri.toURL();
130-
this.cleanedUrl = getCleanedUrl(this.url, this.uri.toString());
131129
}
132130
catch (URISyntaxException ex) {
133131
MalformedURLException exToThrow = new MalformedURLException(ex.getMessage());
@@ -144,7 +142,7 @@ public UrlResource(String protocol, String location, @Nullable String fragment)
144142
* @return the cleaned URL (possibly the original URL as-is)
145143
* @see org.springframework.util.StringUtils#cleanPath
146144
*/
147-
private URL getCleanedUrl(URL originalUrl, String originalPath) {
145+
private static URL getCleanedUrl(URL originalUrl, String originalPath) {
148146
String cleanedPath = StringUtils.cleanPath(originalPath);
149147
if (!cleanedPath.equals(originalPath)) {
150148
try {
@@ -157,6 +155,21 @@ private URL getCleanedUrl(URL originalUrl, String originalPath) {
157155
return originalUrl;
158156
}
159157

158+
/**
159+
* Lazily determine a cleaned URL for the given original URL.
160+
* @see #getCleanedUrl(URL, String)
161+
*/
162+
private URL getCleanedUrl() {
163+
URL cleanedUrl = this.cleanedUrl;
164+
if (cleanedUrl != null) {
165+
return cleanedUrl;
166+
}
167+
cleanedUrl = getCleanedUrl(this.url, (this.uri != null ? this.uri : this.url).toString());
168+
this.cleanedUrl = cleanedUrl;
169+
return cleanedUrl;
170+
}
171+
172+
160173
/**
161174
* This implementation opens an InputStream for the given URL.
162175
* <p>It sets the {@code useCaches} flag to {@code false},
@@ -262,7 +275,7 @@ protected URL createRelativeURL(String relativePath) throws MalformedURLExceptio
262275
*/
263276
@Override
264277
public String getFilename() {
265-
return StringUtils.getFilename(this.cleanedUrl.getPath());
278+
return StringUtils.getFilename(getCleanedUrl().getPath());
266279
}
267280

268281
/**
@@ -280,15 +293,15 @@ public String getDescription() {
280293
@Override
281294
public boolean equals(@Nullable Object other) {
282295
return (this == other || (other instanceof UrlResource &&
283-
this.cleanedUrl.equals(((UrlResource) other).cleanedUrl)));
296+
getCleanedUrl().equals(((UrlResource) other).getCleanedUrl())));
284297
}
285298

286299
/**
287300
* This implementation returns the hash code of the underlying URL reference.
288301
*/
289302
@Override
290303
public int hashCode() {
291-
return this.cleanedUrl.hashCode();
304+
return getCleanedUrl().hashCode();
292305
}
293306

294307
}

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java

Lines changed: 25 additions & 1 deletion
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.
@@ -18,6 +18,7 @@
1818

1919
import java.sql.Connection;
2020
import java.sql.SQLException;
21+
import java.util.Collections;
2122
import java.util.HashMap;
2223
import java.util.Map;
2324

@@ -164,6 +165,29 @@ else if (dataSource instanceof String) {
164165
}
165166
}
166167

168+
/**
169+
* Return the resolved target DataSources that this router manages.
170+
* @return an unmodifiable map of resolved lookup keys and DataSources
171+
* @throws IllegalStateException if the target DataSources are not resolved yet
172+
* @since 5.2.9
173+
* @see #setTargetDataSources
174+
*/
175+
public Map<Object, DataSource> getResolvedDataSources() {
176+
Assert.state(this.resolvedDataSources != null, "DataSources not resolved yet - call afterPropertiesSet");
177+
return Collections.unmodifiableMap(this.resolvedDataSources);
178+
}
179+
180+
/**
181+
* Return the resolved default target DataSource, if any.
182+
* @return the default DataSource, or {@code null} if none or not resolved yet
183+
* @since 5.2.9
184+
* @see #setDefaultTargetDataSource
185+
*/
186+
@Nullable
187+
public DataSource getResolvedDefaultDataSource() {
188+
return this.resolvedDefaultDataSource;
189+
}
190+
167191

168192
@Override
169193
public Connection getConnection() throws SQLException {

spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketRequesterMethodArgumentResolver.java

Lines changed: 2 additions & 2 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.
@@ -60,7 +60,7 @@ public Mono<Object> resolveArgument(MethodParameter parameter, Message<?> messag
6060
return Mono.just(requester);
6161
}
6262
else if (RSocket.class.isAssignableFrom(type)) {
63-
return Mono.just(requester.rsocket());
63+
return Mono.justOrEmpty(requester.rsocket());
6464
}
6565
else {
6666
return Mono.error(new IllegalArgumentException("Unexpected parameter type: " + parameter));

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java

Lines changed: 1 addition & 3 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.
@@ -85,7 +85,6 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
8585
}
8686

8787
@Override
88-
@SuppressWarnings("unchecked")
8988
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
9089
String attributeName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
9190
return exchange.getAttributeOrDefault(attributeName, Collections.emptyMap()).get(name);
@@ -97,7 +96,6 @@ protected void handleMissingValue(String name, MethodParameter parameter) {
9796
}
9897

9998
@Override
100-
@SuppressWarnings("unchecked")
10199
protected void handleResolvedValue(
102100
@Nullable Object arg, String name, MethodParameter parameter, Model model, ServerWebExchange exchange) {
103101

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ else if (interceptor instanceof WebRequestInterceptor) {
444444

445445
/**
446446
* Return the adapted interceptors as {@link HandlerInterceptor} array.
447-
* @return the array of {@link HandlerInterceptor HandlerInterceptors}, or
448-
* {@code null} if none
447+
* @return the array of {@link HandlerInterceptor HandlerInterceptor}s,
448+
* or {@code null} if none
449449
*/
450450
@Nullable
451451
protected final HandlerInterceptor[] getAdaptedInterceptors() {
@@ -572,7 +572,7 @@ protected String initLookupPath(HttpServletRequest request) {
572572
* Build a {@link HandlerExecutionChain} for the given handler, including
573573
* applicable interceptors.
574574
* <p>The default implementation builds a standard {@link HandlerExecutionChain}
575-
* with the given handler, the handler mappings common interceptors, and any
575+
* with the given handler, the common interceptors of the handler mapping, and any
576576
* {@link MappedInterceptor MappedInterceptors} matching to the current request URL. Interceptors
577577
* are added in the order they were registered. Subclasses may override this
578578
* in order to extend/rearrange the list of interceptors.
@@ -652,7 +652,7 @@ protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest
652652
HandlerExecutionChain chain, @Nullable CorsConfiguration config) {
653653

654654
if (CorsUtils.isPreFlightRequest(request)) {
655-
List<HandlerInterceptor> interceptors = chain.getInterceptorList();
655+
HandlerInterceptor[] interceptors = chain.getInterceptors();
656656
return new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
657657
}
658658
else {

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java

Lines changed: 1 addition & 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.

0 commit comments

Comments
 (0)