diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarFileUrlKey.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarFileUrlKey.java index d1ba28fa087..84c55435599 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarFileUrlKey.java +++ b/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"); * you may not use this file except in compliance with the License. @@ -41,6 +41,9 @@ final class JarFileUrlKey { * @return a {@link JarFileUrlKey} instance */ static String get(URL url) { + if (!isCachableUrl(url)) { + return create(url); + } Map cache = (JarFileUrlKey.cache != null) ? JarFileUrlKey.cache.get() : null; if (cache == null) { cache = new ConcurrentHashMap<>(); @@ -49,6 +52,11 @@ final class JarFileUrlKey { 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) { StringBuilder value = new StringBuilder(); String protocol = url.getProtocol();