Browse Source

Merge branch '3.3.x' into 3.4.x

Closes gh-46027
pull/45853/head
Phillip Webb 6 months ago
parent
commit
aa4bf73464
  1. 10
      spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarFileUrlKey.java

10
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarFileUrlKey.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2024 the original author or authors. * Copyright 2012-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -41,6 +41,9 @@ final class JarFileUrlKey {
* @return a {@link JarFileUrlKey} instance * @return a {@link JarFileUrlKey} instance
*/ */
static String get(URL url) { static String get(URL url) {
if (!isCachableUrl(url)) {
return create(url);
}
Map<URL, String> cache = (JarFileUrlKey.cache != null) ? JarFileUrlKey.cache.get() : null; Map<URL, String> cache = (JarFileUrlKey.cache != null) ? JarFileUrlKey.cache.get() : null;
if (cache == null) { if (cache == null) {
cache = new ConcurrentHashMap<>(); cache = new ConcurrentHashMap<>();
@ -49,6 +52,11 @@ final class JarFileUrlKey {
return cache.computeIfAbsent(url, JarFileUrlKey::create); return cache.computeIfAbsent(url, JarFileUrlKey::create);
} }
private static boolean isCachableUrl(URL url) {
// Don't cache URL that have a host since equals() will perform DNS lookup
return url.getHost() == null || url.getHost().isEmpty();
}
private static String create(URL url) { private static String create(URL url) {
StringBuilder value = new StringBuilder(); StringBuilder value = new StringBuilder();
String protocol = url.getProtocol(); String protocol = url.getProtocol();

Loading…
Cancel
Save