Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE in ApacheHttpClientApiAdapter#getHostName - Spring 6.1 RestClient #3478

Closed
NicklasWallgren opened this issue Dec 28, 2023 · 1 comment · Fixed by #3479
Closed

NPE in ApacheHttpClientApiAdapter#getHostName - Spring 6.1 RestClient #3478

NicklasWallgren opened this issue Dec 28, 2023 · 1 comment · Fixed by #3479
Labels
agent-java community Issues and PRs created by the community triage

Comments

@NicklasWallgren
Copy link
Contributor

The new RestClient that is part of Spring 6.1 sends the HttpHost target as null which isn't handled by the ApacheHttpClient5ApiAdapter#getHostName method. The interface for the HttpClient allows the target to be null.

Stacktrace

java.lang.NullPointerException: Cannot invoke "org.apache.hc.core5.http.HttpHost.getHostName()" because "httpHost" is null
	at co.elastic.apm.agent.httpclient.v5.helper.ApacheHttpClient5ApiAdapter.getHostName(ApacheHttpClient5ApiAdapter.java:53) ~[elastic-apm-agent-c0c4fc57bb13f1eb30fc0769cc96e7ab-ac8d1c4ecac81aabe5e989b93c598194.jar:1.45.0]
	at co.elastic.apm.agent.httpclient.v5.helper.ApacheHttpClient5ApiAdapter.getHostName(ApacheHttpClient5ApiAdapter.java:31) ~[elastic-apm-agent-c0c4fc57bb13f1eb30fc0769cc96e7ab-ac8d1c4ecac81aabe5e989b93c598194.jar:1.45.0]
	at co.elastic.apm.agent.httpclient.common.AbstractApacheHttpClientAdvice.startSpan(AbstractApacheHttpClientAdvice.java:44) ~[elastic-apm-agent-c0c4fc57bb13f1eb30fc0769cc96e7ab-ac8d1c4ecac81aabe5e989b93c598194.jar:1.45.0]
	at co.elastic.apm.agent.httpclient.v5.ApacheHttpClient5Instrumentation$ApacheHttpClient5Advice.onBeforeExecute(ApacheHttpClient5Instrumentation.java:53) ~[elastic-apm-agent-c0c4fc57bb13f1eb30fc0769cc96e7ab-ac8d1c4ecac81aabe5e989b93c598194.jar:1.45.0]
	at org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:146) ~[httpclient5-5.2.1.jar:5.2.1]
	at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:87) ~[httpclient5-5.2.1.jar:5.2.1]
	at org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:55) ~[httpclient5-5.2.1.jar:5.2.1]
	at org.apache.hc.client5.http.classic.HttpClient.executeOpen(HttpClient.java:183) ~[httpclient5-5.2.1.jar:5.2.1]
	at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:95) ~[spring-web-6.1.1.jar:6.1.1]
	at org.springframework.http.client.AbstractStreamingClientHttpRequest.executeInternal(AbstractStreamingClientHttpRequest.java:70) ~[spring-web-6.1.1.jar:6.1.1]
	at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66) ~[spring-web-6.1.1.jar:6.1.1]
	at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:453) ~[spring-web-6.1.1.jar:6.1.1]
	at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.retrieve(DefaultRestClient.java:424) ~[spring-web-6.1.1.jar:6.1.1]

@jackshirazi
Copy link
Contributor

jackshirazi commented Jan 4, 2024

Thanks for raising this, we'll schedule the bugfix - and thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-java community Issues and PRs created by the community triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants