elastic / apm-agent-java

Home Page:https://www.elastic.co/guide/en/apm/agent/java/current/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NPE in ApacheHttpClientApiAdapter#getHostName - Spring 6.1 RestClient

NicklasWallgren opened this issue · comments

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]

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