From 901e8d8423b94a2ad8cd2082f8b55fd780eeac59 Mon Sep 17 00:00:00 2001 From: simonlei Date: Fri, 6 Nov 2020 07:54:58 +0800 Subject: [PATCH] Fix issue #5795 (#5797) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix issue #5795 Fix the issue: nutz plugin throw NPE at afterMethod, cause traceid keep unchange for the thread * fix the style and modify the CHANGES.md Co-authored-by: 吴晟 Wu Sheng Co-authored-by: simonlei Co-authored-by: kezhenxu94 --- CHANGES.md | 1 + .../apm/plugin/nutz/http/sync/SenderSendInterceptor.java | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5844d13ec..008355af9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Release Notes. * Make the okhttp3 plugin to support Java 14 * Polish tracing context related codes. * Add the plugin for async-http-client 2.x +* Fix NPE in the nutz plugin. #### OAP-Backend * Add the `@SuperDataset` annotation for BrowserErrorLog. diff --git a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java index af6fae60f..22faeeed6 100644 --- a/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/nutz-plugins/http-1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/nutz/http/sync/SenderSendInterceptor.java @@ -63,11 +63,12 @@ public class SenderSendInterceptor implements InstanceMethodsAroundInterceptor { public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments, final Class[] argumentsTypes, Object ret) throws Throwable { Response response = (Response) ret; - int statusCode = response.getStatus(); AbstractSpan span = ContextManager.activeSpan(); - if (statusCode >= 400) { + + if (response == null || response.getStatus() >= 400) { span.errorOccurred(); - Tags.STATUS_CODE.set(span, Integer.toString(statusCode)); + if (response != null) + Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus())); } ContextManager.stopSpan(); return ret;