From edc69ed8476826315208362c676e2b214eb3ae0b Mon Sep 17 00:00:00 2001 From: xzyJavaX <49760141+xzyJavaX@users.noreply.github.com> Date: Fri, 29 Apr 2022 12:53:14 +0800 Subject: [PATCH] Fix NPE in elasticsearch plugin (#167) --- CHANGES.md | 1 + .../AdapterActionFutureActionGetMethodsInterceptor.java | 4 +++- .../AdapterActionFutureActionGetMethodsInterceptor.java | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 10f0475ee..8945f8364 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Release Notes. * Fix NPE in gateway plugin when the timer triggers webflux webclient call. * Add an optional plugin, trace-sampler-cpu-policy-plugin, which could disable trace collecting in high CPU load. * Change the dateformat of logs to `yyyy-MM-dd HH:mm:ss.SSS`(was `yyyy-MM-dd HH:mm:ss:SSS`). +* Fix NPE in elasticsearch plugin. #### Documentation diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java index bee05a636..152238352 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-6.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v6/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java @@ -66,7 +66,9 @@ public class AdapterActionFutureActionGetMethodsInterceptor implements InstanceM @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().log(t); + if (isTrace(objInst)) { + ContextManager.activeSpan().log(t); + } } private boolean isTrace(EnhancedInstance objInst) { diff --git a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java index fb19d3483..47f0b8d10 100644 --- a/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/elasticsearch-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/elasticsearch/v7/interceptor/AdapterActionFutureActionGetMethodsInterceptor.java @@ -67,7 +67,9 @@ public class AdapterActionFutureActionGetMethodsInterceptor implements InstanceM @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Throwable t) { - ContextManager.activeSpan().log(t); + if (isTrace(objInst)) { + ContextManager.activeSpan().log(t); + } } private boolean isTrace(EnhancedInstance objInst) {