Browse Source

Never attempt to resolve local address for nested URLs

Update `nested:` Handler to always return `null` from `getHostAddress`
in an attempt to improve performance on Windows.

Fixes gh-46063
pull/46211/head
Phillip Webb 7 months ago
parent
commit
2128a84492
  1. 8
      spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/nested/Handler.java
  2. 7
      spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/net/protocol/nested/HandlerTests.java

8
spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/nested/Handler.java

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.boot.loader.net.protocol.nested;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
@ -35,6 +36,13 @@ public class Handler extends URLStreamHandler { @@ -35,6 +36,13 @@ public class Handler extends URLStreamHandler {
private static final String PREFIX = "nested:";
@Override
protected InetAddress getHostAddress(URL url) {
// Some Windows users have reported that calls to java.net.URL.getHostAddress()
// can be slow. Since we only deal with local files we always return null here.
return null;
}
@Override
protected URLConnection openConnection(URL url) throws IOException {
return new NestedUrlConnection(url);

7
spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/net/protocol/nested/HandlerTests.java

@ -68,4 +68,11 @@ class HandlerTests { @@ -68,4 +68,11 @@ class HandlerTests {
assertThatNoException().isThrownBy(() -> Handler.assertUrlIsNotMalformed(url));
}
@Test
void getHostAddressIsNull() throws Exception {
// gh-46063
String url = "nested:" + this.temp.getAbsolutePath() + "/!nested.jar";
assertThat(new Handler().getHostAddress(new URL(url))).isNull();
}
}

Loading…
Cancel
Save