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
This commit is contained in:
Juergen Hoeller
2020-08-07 13:15:36 +02:00
9 changed files with 64 additions and 28 deletions

View File

@@ -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.
* <p>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()

View File

@@ -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.
* <p>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();
}
}