From d1958154880f984b70bf6929e5de2746182cc533 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 16 Dec 2020 15:44:52 -0800 Subject: [PATCH] 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 7938b9eb7c0b..e2daf9bde365 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 void start() throws WebServerException { } 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); } });