From c082a3f87d02e9edd0cce59d8eee733f99eb0a40 Mon Sep 17 00:00:00 2001 From: songy23 Date: Thu, 18 Jan 2018 17:35:41 -0800 Subject: [PATCH] A workaround to pass null analysis --- .../stackdriver/StackdriverExporterWorker.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExporterWorker.java b/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExporterWorker.java index d710e0fcd5..ef7b4cf7af 100644 --- a/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExporterWorker.java +++ b/exporters/stats/stackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExporterWorker.java @@ -21,6 +21,7 @@ import com.google.api.gax.rpc.ApiException; import com.google.cloud.monitoring.v3.MetricServiceClient; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.monitoring.v3.CreateMetricDescriptorRequest; import com.google.monitoring.v3.CreateTimeSeriesRequest; @@ -41,6 +42,7 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import javax.annotation.CheckForNull; import javax.annotation.concurrent.NotThreadSafe; /*>>> @@ -182,11 +184,16 @@ void export() { metricServiceClient.createTimeSeries(request); span.addAnnotation("Finish exporting TimeSeries."); } catch (com.google.api.gax.rpc.UnavailableException e) { - if (e.getLocalizedMessage() != null - && e.getLocalizedMessage() - .startsWith( - "io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP/2 error code: NO_ERROR")) { - continue; // Silently skip NO_ERROR Goaway + if (e.getLocalizedMessage() != null) { + String message = e.getLocalizedMessage(); + if (message == null) { + throw new AssertionError(); // To pass null check + } + if (message + .startsWith( + "io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP/2 error code: NO_ERROR")) { + continue; // Silently skip NO_ERROR Goaway + } } else { logAndSetSpanStatusForApiException(e, span); }