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
This commit is contained in:
Phillip Webb 2020-12-16 15:44:52 -08:00
parent 7f51984cbd
commit b2abc8ff3f
1 changed files with 1 additions and 1 deletions

View File

@ -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);
}
});