diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index 6731ed5b45f..a3b30da5668 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -325,9 +325,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto this.allowBeanDefinitionOverriding = otherListableFactory.allowBeanDefinitionOverriding; this.allowEagerClassLoading = otherListableFactory.allowEagerClassLoading; this.dependencyComparator = otherListableFactory.dependencyComparator; - // A clone of the AutowireCandidateResolver since it is potentially BeanFactoryAware... + // A clone of the AutowireCandidateResolver since it is potentially BeanFactoryAware setAutowireCandidateResolver(otherListableFactory.getAutowireCandidateResolver().cloneIfNecessary()); - // Make resolvable dependencies (e.g. ResourceLoader) available here as well... + // Make resolvable dependencies (e.g. ResourceLoader) available here as well this.resolvableDependencies.putAll(otherListableFactory.resolvableDependencies); } } @@ -462,6 +462,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } } } + @SuppressWarnings("unchecked") @Override @SuppressWarnings("unchecked") public Stream stream() { @@ -469,6 +470,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto .map(name -> (T) getBean(name)) .filter(bean -> !(bean instanceof NullBean)); } + @SuppressWarnings("unchecked") @Override @SuppressWarnings("unchecked") public Stream orderedStream() { diff --git a/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java b/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java index 2e1d67fea19..28beb6da531 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java +++ b/spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java @@ -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. @@ -55,8 +55,7 @@ public abstract class AbstractValueAdaptingCache implements Cache { @Override @Nullable public ValueWrapper get(Object key) { - Object value = lookup(key); - return toValueWrapper(value); + return toValueWrapper(lookup(key)); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java b/spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java index 99f0d95874d..4e1b0fa8093 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java @@ -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. @@ -52,7 +52,7 @@ public class FileUrlResource extends UrlResource implements WritableResource { /** * Create a new {@code FileUrlResource} based on the given URL object. *

Note that this does not enforce "file" as URL protocol. If a protocol - * is known to be resolvable to a file, + * is known to be resolvable to a file, it is acceptable for this purpose. * @param url a URL * @see ResourceUtils#isFileURL(URL) * @see #getFile() diff --git a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java index b989384a019..3f1dcc05ffe 100644 --- a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java @@ -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. @@ -56,7 +56,8 @@ public class UrlResource extends AbstractFileResolvingResource { /** * Cleaned URL (with normalized path), used for comparisons. */ - private final URL cleanedUrl; + @Nullable + private volatile URL cleanedUrl; /** @@ -69,7 +70,6 @@ public class UrlResource extends AbstractFileResolvingResource { Assert.notNull(uri, "URI must not be null"); this.uri = uri; this.url = uri.toURL(); - this.cleanedUrl = getCleanedUrl(this.url, uri.toString()); } /** @@ -78,9 +78,8 @@ public class UrlResource extends AbstractFileResolvingResource { */ public UrlResource(URL url) { Assert.notNull(url, "URL must not be null"); - this.url = url; - this.cleanedUrl = getCleanedUrl(this.url, url.toString()); this.uri = null; + this.url = url; } /** @@ -127,7 +126,6 @@ public class UrlResource extends AbstractFileResolvingResource { try { this.uri = new URI(protocol, location, fragment); this.url = this.uri.toURL(); - this.cleanedUrl = getCleanedUrl(this.url, this.uri.toString()); } catch (URISyntaxException ex) { MalformedURLException exToThrow = new MalformedURLException(ex.getMessage()); @@ -144,7 +142,7 @@ public class UrlResource extends AbstractFileResolvingResource { * @return the cleaned URL (possibly the original URL as-is) * @see org.springframework.util.StringUtils#cleanPath */ - private URL getCleanedUrl(URL originalUrl, String originalPath) { + private static URL getCleanedUrl(URL originalUrl, String originalPath) { String cleanedPath = StringUtils.cleanPath(originalPath); if (!cleanedPath.equals(originalPath)) { try { @@ -157,6 +155,21 @@ public class UrlResource extends AbstractFileResolvingResource { return originalUrl; } + /** + * Lazily determine a cleaned URL for the given original URL. + * @see #getCleanedUrl(URL, String) + */ + private URL getCleanedUrl() { + URL cleanedUrl = this.cleanedUrl; + if (cleanedUrl != null) { + return cleanedUrl; + } + cleanedUrl = getCleanedUrl(this.url, (this.uri != null ? this.uri : this.url).toString()); + this.cleanedUrl = cleanedUrl; + return cleanedUrl; + } + + /** * This implementation opens an InputStream for the given URL. *

It sets the {@code useCaches} flag to {@code false}, @@ -262,7 +275,7 @@ public class UrlResource extends AbstractFileResolvingResource { */ @Override public String getFilename() { - return StringUtils.getFilename(this.cleanedUrl.getPath()); + return StringUtils.getFilename(getCleanedUrl().getPath()); } /** @@ -280,7 +293,7 @@ public class UrlResource extends AbstractFileResolvingResource { @Override public boolean equals(@Nullable Object other) { return (this == other || (other instanceof UrlResource && - this.cleanedUrl.equals(((UrlResource) other).cleanedUrl))); + getCleanedUrl().equals(((UrlResource) other).getCleanedUrl()))); } /** @@ -288,7 +301,7 @@ public class UrlResource extends AbstractFileResolvingResource { */ @Override public int hashCode() { - return this.cleanedUrl.hashCode(); + return getCleanedUrl().hashCode(); } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java index b89bb1abeb8..88669594b10 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java @@ -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. @@ -18,6 +18,7 @@ package org.springframework.jdbc.datasource.lookup; import java.sql.Connection; import java.sql.SQLException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -164,6 +165,29 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple } } + /** + * Return the resolved target DataSources that this router manages. + * @return an unmodifiable map of resolved lookup keys and DataSources + * @throws IllegalStateException if the target DataSources are not resolved yet + * @since 5.2.9 + * @see #setTargetDataSources + */ + public Map getResolvedDataSources() { + Assert.state(this.resolvedDataSources != null, "DataSources not resolved yet - call afterPropertiesSet"); + return Collections.unmodifiableMap(this.resolvedDataSources); + } + + /** + * Return the resolved default target DataSource, if any. + * @return the default DataSource, or {@code null} if none or not resolved yet + * @since 5.2.9 + * @see #setDefaultTargetDataSource + */ + @Nullable + public DataSource getResolvedDefaultDataSource() { + return this.resolvedDefaultDataSource; + } + @Override public Connection getConnection() throws SQLException { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketRequesterMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketRequesterMethodArgumentResolver.java index dbba09d3c20..b5598b34c25 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketRequesterMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketRequesterMethodArgumentResolver.java @@ -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. @@ -60,7 +60,7 @@ public class RSocketRequesterMethodArgumentResolver implements HandlerMethodArgu return Mono.just(requester); } else if (RSocket.class.isAssignableFrom(type)) { - return Mono.just(requester.rsocket()); + return Mono.justOrEmpty(requester.rsocket()); } else { return Mono.error(new IllegalArgumentException("Unexpected parameter type: " + parameter)); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java index 8096a8adf9f..2d53ad24c31 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/PathVariableMethodArgumentResolver.java @@ -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. @@ -85,7 +85,6 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueSyncAr } @Override - @SuppressWarnings("unchecked") protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { String attributeName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE; return exchange.getAttributeOrDefault(attributeName, Collections.emptyMap()).get(name); @@ -97,7 +96,6 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueSyncAr } @Override - @SuppressWarnings("unchecked") protected void handleResolvedValue( @Nullable Object arg, String name, MethodParameter parameter, Model model, ServerWebExchange exchange) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index 1a12cb6010e..ae3c5afbd5e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -444,8 +444,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport /** * Return the adapted interceptors as {@link HandlerInterceptor} array. - * @return the array of {@link HandlerInterceptor HandlerInterceptors}, or - * {@code null} if none + * @return the array of {@link HandlerInterceptor HandlerInterceptor}s, + * or {@code null} if none */ @Nullable protected final HandlerInterceptor[] getAdaptedInterceptors() { @@ -572,7 +572,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * Build a {@link HandlerExecutionChain} for the given handler, including * applicable interceptors. *

The default implementation builds a standard {@link HandlerExecutionChain} - * with the given handler, the handler mappings common interceptors, and any + * with the given handler, the common interceptors of the handler mapping, and any * {@link MappedInterceptor MappedInterceptors} matching to the current request URL. Interceptors * are added in the order they were registered. Subclasses may override this * in order to extend/rearrange the list of interceptors. @@ -652,7 +652,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport HandlerExecutionChain chain, @Nullable CorsConfiguration config) { if (CorsUtils.isPreFlightRequest(request)) { - List interceptors = chain.getInterceptorList(); + HandlerInterceptor[] interceptors = chain.getInterceptors(); return new HandlerExecutionChain(new PreFlightHandler(config), interceptors); } else { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java index 07a24dbdc84..557bf7801e8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java @@ -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.