Skip to content

Conversation

@spartusch
Copy link
Contributor

@spartusch spartusch commented Dec 23, 2020

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

The interface org.springframework.boot.web.server.WebServer defines
that getPort() returns -1 if the server isn't listening on a port. This
commit changes the implementations of the interface accordingly.

See spring-projectsgh-24540
Copy link

@J4NS-R J4NS-R left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thorough work.

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 4, 2021
@philwebb philwebb modified the milestones: 2.4.2, 2.3.x Jan 4, 2021
@philwebb philwebb changed the title Let WebServer implementations return port -1 if not listening on a port WebServer implementations should return -1 if not listening on a port Jan 5, 2021
@philwebb philwebb self-assigned this Jan 5, 2021
philwebb pushed a commit that referenced this pull request Jan 6, 2021
Update `WebServer` implementations to return -1 from `getPort()` if
the server  isn't listening on a port. This aligns the implementations
with the interface Javadoc.

See gh-24606
philwebb added a commit that referenced this pull request Jan 6, 2021
@philwebb philwebb modified the milestones: 2.3.x, 2.3.8 Jan 6, 2021
@philwebb philwebb closed this in 7825921 Jan 6, 2021
@philwebb
Copy link
Member

philwebb commented Jan 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants