Skip to content

Fix NPE in InternalAbstractHttpAsyncClient by adding null check for resolvedTarget - #634

Merged
arturobernalg merged 1 commit into
apache:masterfrom
arturobernalg:HTTPCLIENT-2367
May 2, 2025
Merged

arturobernalg merged 1 commit into
apache:masterfrom
arturobernalg:HTTPCLIENT-2367

Conversation

@arturobernalg

Copy link
Copy Markdown
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) {

@garydgregory garydgregory May 1, 2025 •

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.

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
Copy Markdown
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
Copy Markdown
Member Author

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

@ok2c

ok2c commented May 2, 2025

Copy link
Copy Markdown
Member

@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
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

ok2c commented May 2, 2025

Copy link
Copy Markdown
Member

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

@garydgregory

Copy link
Copy Markdown
Member

👍

@arturobernalg

Copy link
Copy Markdown
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