Skip to content

GH-1271: [Flight] Reject port 0 in NettyClientBuilder - #1282

Open
ennuite wants to merge 3 commits into
apache:mainfrom
ennuite:remove-port-zero
Open

GH-1271: [Flight] Reject port 0 in NettyClientBuilder#1282
ennuite wants to merge 3 commits into
apache:mainfrom
ennuite:remove-port-zero

Conversation

@ennuite

@ennuite ennuite commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

What's changed

Port validation in NettyClientBuilder.build() is tightened to explicitly disallow port 0, as it is not a valid destination port number for a client.
Tests that made use of port 0 were updated to use a valid port under the new validation.

Are these changes tested?

Yes. ConnectionTest.testUnencryptedConnectionProvidingInvalidPort was expanded to cover more invalid ports, including port 0.

This change was created with AI assistance (Claude Code). All lines were manually reviewed by a human. The output is not copyrightable subject matter.

Closes #1271.

ennuite and others added 3 commits August 31, 2026 16:19
… omitted port

Tighten the port validation to 1–65535 (port 0 is reserved and invalid
for client connections). Four builder-based tests were not calling
withPort() at all, so the port field defaulted to 0 and slipped through
unnoticed before the validation was added. Each test now passes the
actual test-server port via FLIGHT_SERVER_TEST_EXTENSION.getPort().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Converts testUnencryptedConnectionProvidingInvalidPort to a
@ParameterizedTest covering 0, -1, 65536, and 65537, explicitly
exercising the port-0 rejection added to NettyClientBuilder.build().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ennuite
ennuite marked this pull request as draft August 31, 2026 15:21
@ennuite ennuite changed the title GH-1271: Reject port 0 in NettyClientBuilder and fix tests that omitted port GH-1271: [Flight] Reject port 0 in NettyClientBuilder Aug 31, 2026
@ennuite
ennuite marked this pull request as ready for review August 31, 2026 15:30
@ennuite

ennuite commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

No need from my side to add this one to release 20.0.0

It needs the enhancement label.

@github-actions

This comment has been minimized.

{
final int port = location.getUri().getPort();
if (port < 0 || port > 65535) {
if (port < 1 || port > 65535) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

URI.getPort() returns -1 to mean "no port present in the URI", not "the user asked for port -1".
Folding it into this range check produces Invalid port -1: must be between 1 and 65535 (a number that the user never defined).

That path is reachable: a Location like grpc+tls://myhost with no port, and also ArrowFlightSqlClientHandler.getStreams(), which does withPort(endpointUri.getPort()) on an endpoint URI that may carry no port.

Since this PR is rewriting the message anyway, this seems like the moment to split
the two cases:

if (port == -1) {
  throw new IllegalArgumentException(
      "No port specified in location URI: " + location.getUri());
}
if (port < 1 || port > 65535) {
  throw new IllegalArgumentException(
      "Invalid port " + port + ": must be between 1 and 65535.");
}

if (port < 1 || port > 65535) {
throw new IllegalArgumentException(
"Invalid port " + port + ": must be between 0 and 65535.");
"Invalid port " + port + ": must be between 1 and 65535.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This narrows the accepted input range of published public API: NettyClientBuilder,
and transitively FlightClient.Builder. Third-party code that today calls FlightClient.builder(allocator, someLocation).build() with a port-0 location
(a server location captured before start(), or a placeholder resolved later) gets a lazily-failing channel today and an immediate IllegalArgumentException after this.

The change itself is right, but neither NettyClientBuilder.build() nor
FlightClient.Builder.build() documents the precondition.

Could we add an @throws IllegalArgumentException javadoc stating the accepted range, so callers can
discover it without hitting it in production?

@jbonofre jbonofre added the enhancement PRs that add or improve features. label Sep 1, 2026
@jbonofre jbonofre added this to the 20.0.0 milestone Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement PRs that add or improve features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flight] Reject port 0 in NettyClientBuilder

2 participants