The interface org.springframework.boot.web.server.WebServer defines that getPort() returns -1 if the server isn't listening on a port. But the current implementations of the interface return 0 instead. This changes the implementations to return -1.

Please note: Jetty itself does return -2 as the local port after the connection has been closed. Therefore in its implementation getPort() maps all local ports <= 0 to -1 to match the method's contract.

See #24540

Comment From: philwebb

Thanks very much for the compressive PR @spartusch. This has been merged to 2.3.x, 2.4.x and master.