From 361198ebba05c963082f7c205b4b117a631e49ab Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Wed, 16 Dec 2020 15:25:02 -0800 Subject: [PATCH 1/2] Fix tests See gh-11987 --- .../servlet/ManagementWebSecurityAutoConfigurationTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java index fd988102f1..ec3cbd6cf4 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java @@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration; import org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.context.annotation.Configuration; @@ -56,7 +57,7 @@ class ManagementWebSecurityAutoConfigurationTests { private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner().withConfiguration( AutoConfigurations.of(HealthContributorAutoConfiguration.class, HealthEndpointAutoConfiguration.class, InfoEndpointAutoConfiguration.class, EnvironmentEndpointAutoConfiguration.class, - EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class, + EndpointAutoConfiguration.class, WebMvcAutoConfiguration.class, WebEndpointAutoConfiguration.class, SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class)); @Test From b2abc8ff3f930ae4e052daaeedcd48b30428d8cf Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 16 Dec 2020 15:44:52 -0800 Subject: [PATCH 2/2] Only throw PortInUseException if port is set Refine the `PortInUseException` logic in `NettyWebServer` to only throw an exception if the port is set. The prevents a misleading exception from being thrown when a domain socket is being used. Closes gh-24529 --- .../springframework/boot/web/embedded/netty/NettyWebServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java index 7938b9eb7c..e2daf9bde3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java @@ -101,7 +101,7 @@ public class NettyWebServer implements WebServer { } catch (Exception ex) { PortInUseException.ifCausedBy(ex, ChannelBindException.class, (bindException) -> { - if (!isPermissionDenied(bindException.getCause())) { + if (bindException.localPort() > 0 && !isPermissionDenied(bindException.getCause())) { throw new PortInUseException(bindException.localPort(), ex); } });