Skip to content

Conversation

@arturobernalg
Copy link
Member

Resolves a NullPointerException in InternalAbstractHttpAsyncClient by adding a null check for resolvedTarget when RoutingSupport.determineHost returns null. Throws IllegalStateException for invalid requests, ensuring robust error handling. Addresses HTTPCLIENT-2367.

@arturobernalg arturobernalg requested a review from ok2c May 1, 2025 12:06
}
if (request.getAuthority() == null) {
request.setAuthority(new URIAuthority(resolvedTarget));
if (resolvedTarget != null) {
Copy link
Member

@garydgregory garydgregory May 1, 2025

Choose a reason for hiding this comment

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

HI @arturobernalg 👋
We could throw a more precise exception using Objects.requireNonNull(...), which would reduce the nesting. See also org.apache.hc.core5.util.Args.notNull(T, String)

@arturobernalg arturobernalg force-pushed the HTTPCLIENT-2367 branch 4 times, most recently from db53767 to 622c043 Compare May 2, 2025 06:23
setupContext(clientContext);

final HttpHost resolvedTarget = target != null ? target : RoutingSupport.determineHost(request);
Args.notNull(resolvedTarget, "Target host for the request");
Copy link
Member

Choose a reason for hiding this comment

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

@arturobernalg This is not right. The target may be null if the request URI cannot be parsed. It should be up to the specific protocol handler to decide if such a request can be executed. H2 will likely reject it but HTTP/1.1 may accept it

@arturobernalg arturobernalg requested a review from ok2c May 2, 2025 10:02
@arturobernalg
Copy link
Member Author

@ok2c should I wait for the original reporter’s feedback before merging?

@ok2c
Copy link
Member

ok2c commented May 2, 2025

@ok2c should I wait for the original reporter’s feedback before merging?

@arturobernalg I do not think it is necessary. The fix is quite straight-forward.

@arturobernalg arturobernalg merged commit 048ff8a into apache:master May 2, 2025
10 checks passed
ok2c pushed a commit that referenced this pull request May 2, 2025
ok2c pushed a commit that referenced this pull request May 2, 2025
@ok2c
Copy link
Member

ok2c commented May 2, 2025

@arturobernalg I tweaked the test case a little to make it behave it more similarly to the default route planner.

@garydgregory
Copy link
Member

👍

@arturobernalg
Copy link
Member Author

@arturobernalg I tweaked the test case a little to make it behave it more similarly to the default route planner.

thank you @ok2c

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants