Skip to content

Commit d7de9d2

Browse files
authored
Guarding from null host in Apache legacy HTTP client (#1746)
1 parent 6325628 commit d7de9d2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Even when matching on the main class name or on system properties,
6868
* Fix apm-log4j1-plugin and apm-log4j2-plugin dependency on slf4j - {pull}1723[#1723]
6969
* Avoid systematic `MessageNotWriteableException` error logging, now only visible in `debug` - {pull}1715[#1715]
7070
* Fix rounded number format for non-english locales - {pull}1728[#1728]
71+
* Fix `NullPointerException` on legacy Apache client instrumentation when host is `null` - {pull}1746[#1746]
7172
7273
[[release-notes-1.x]]
7374
=== Java Agent version 1.x

apm-agent-plugins/apm-apache-httpclient-plugin/src/main/java/co/elastic/apm/agent/httpclient/LegacyApacheHttpClientInstrumentation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class LegacyApacheHttpClientInstrumentation extends BaseApacheHttpClientI
5656
public static class LegacyApacheHttpClientAdvice {
5757
@Nullable
5858
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
59-
public static Object onBeforeExecute(@Advice.Argument(0) HttpHost host,
59+
public static Object onBeforeExecute(@Advice.Argument(0) @Nullable HttpHost host,
6060
@Advice.Argument(1) HttpRequest request) {
6161
final AbstractSpan<?> parent = tracer.getActive();
6262
if (parent == null) {
@@ -66,7 +66,8 @@ public static Object onBeforeExecute(@Advice.Argument(0) HttpHost host,
6666
return null;
6767
}
6868
HttpUriRequest uriRequest = (HttpUriRequest) request;
69-
Span span = HttpClientHelper.startHttpClientSpan(parent, uriRequest.getMethod(), uriRequest.getURI(), host.getHostName());
69+
String hostName = (host != null) ? host.getHostName() : null;
70+
Span span = HttpClientHelper.startHttpClientSpan(parent, uriRequest.getMethod(), uriRequest.getURI(), hostName);
7071
if (span != null) {
7172
span.activate();
7273
span.propagateTraceContext(request, RequestHeaderAccessor.INSTANCE);

0 commit comments

Comments
 (0)