From 48777fbfed3cf93819ac383d3e1a2884b51e6044 Mon Sep 17 00:00:00 2001 From: Zhan Su Date: Fri, 13 Sep 2019 11:13:37 -0700 Subject: [PATCH] Make serviceName check null-safe Span object stores `localEndpoint.serviceName` empty string as null so `.isEmpty()` throws NullPointerException. --- .../zipkin2/translation/stackdriver/AttributesExtractor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java b/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java index e7a795b9..5edbbd0d 100644 --- a/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java +++ b/translation-stackdriver/src/main/java/zipkin2/translation/stackdriver/AttributesExtractor.java @@ -80,7 +80,9 @@ Attributes extract(Span zipkinSpan) { } } - if (zipkinSpan.localEndpoint() != null && !zipkinSpan.localEndpoint().serviceName().isEmpty()) { + if (zipkinSpan.localEndpoint() != null && + zipkinSpan.localEndpoint().serviceName() != null && + !zipkinSpan.localEndpoint().serviceName().isEmpty()) { attributes.putAttributeMap( kComponentLabelKey, toAttributeValue(zipkinSpan.localEndpoint().serviceName())); }