(skywalking-java) branch main updated: Fix NPE in handleMethodException method of apm-jdk-threadpool-plugin. (#681) (#682)

2024-04-18 Thread wusheng
This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
 new 1a01047007 Fix NPE in handleMethodException method of 
apm-jdk-threadpool-plugin. (#681) (#682)
1a01047007 is described below

commit 1a010470076ba7f206f4fd6559d04136bea73417
Author: ForrestWang123 <157256498+forrestwang...@users.noreply.github.com>
AuthorDate: Fri Apr 19 08:51:09 2024 +0800

Fix NPE in handleMethodException method of apm-jdk-threadpool-plugin. 
(#681) (#682)

Co-authored-by: forrestwang 
---
 .../plugin/AbstractThreadingPoolInterceptor.java   | 32 --
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git 
a/apm-sniffer/bootstrap-plugins/jdk-threadpool-plugin/src/main/java/org/apache/skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java
 
b/apm-sniffer/bootstrap-plugins/jdk-threadpool-plugin/src/main/java/org/apache/skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java
index c72c1424b5..e11c260f42 100644
--- 
a/apm-sniffer/bootstrap-plugins/jdk-threadpool-plugin/src/main/java/org/apache/skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java
+++ 
b/apm-sniffer/bootstrap-plugins/jdk-threadpool-plugin/src/main/java/org/apache/skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java
@@ -28,22 +28,11 @@ import java.lang.reflect.Method;
 public abstract class AbstractThreadingPoolInterceptor implements 
InstanceMethodsAroundInterceptor {
 @Override
 public void beforeMethod(EnhancedInstance objInst, Method method, Object[] 
allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws 
Throwable {
-if (!ContextManager.isActive()) {
-return;
-}
-
-if (allArguments == null || allArguments.length < 1) {
-return;
-}
-
-Object argument = allArguments[0];
-
-// Avoid duplicate enhancement, such as the case where it has already 
been enhanced by RunnableWrapper or CallableWrapper with toolkit.
-if (argument instanceof EnhancedInstance && ((EnhancedInstance) 
argument).getSkyWalkingDynamicField() instanceof ContextSnapshot) {
+if (notToEnhance(allArguments)) {
 return;
 }
 
-Object wrappedObject = wrap(argument);
+Object wrappedObject = wrap(allArguments[0]);
 if (wrappedObject != null) {
 allArguments[0] = wrappedObject;
 }
@@ -63,10 +52,25 @@ public abstract class AbstractThreadingPoolInterceptor 
implements InstanceMethod
 
 @Override
 public void handleMethodException(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class[] argumentsTypes, Throwable t) {
-if (!ContextManager.isActive()) {
+if (notToEnhance(allArguments)) {
 return;
 }
 
 ContextManager.activeSpan().log(t);
 }
+
+private boolean notToEnhance(Object[] allArguments) {
+if (!ContextManager.isActive()) {
+return true;
+}
+
+if (allArguments == null || allArguments.length < 1) {
+return true;
+}
+
+Object argument = allArguments[0];
+
+// Avoid duplicate enhancement, such as the case where it has already 
been enhanced by RunnableWrapper or CallableWrapper with toolkit.
+return argument instanceof EnhancedInstance && ((EnhancedInstance) 
argument).getSkyWalkingDynamicField() instanceof ContextSnapshot;
+}
 }



(skywalking-java) branch main updated: Fix NPE in handleMethodException method of apm-jdk-threadpool-plugin. (#681)

2024-04-18 Thread wusheng
This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git


The following commit(s) were added to refs/heads/main by this push:
 new ec30b5f53d Fix NPE in handleMethodException method of 
apm-jdk-threadpool-plugin. (#681)
ec30b5f53d is described below

commit ec30b5f53db297b26da4e8df89dec3c9d428ef53
Author: ForrestWang123 <157256498+forrestwang...@users.noreply.github.com>
AuthorDate: Thu Apr 18 21:19:50 2024 +0800

Fix NPE in handleMethodException method of apm-jdk-threadpool-plugin. (#681)

Co-authored-by: forrestwang 
---
 CHANGES.md| 1 +
 .../skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java   | 4 
 2 files changed, 5 insertions(+)

diff --git a/CHANGES.md b/CHANGES.md
index 275c823e94..dfe870b619 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,6 +6,7 @@ Release Notes.
 --
 
 * Remove `idleCount` tag in Alibaba Druid meter plugin.
+* Fix NPE in handleMethodException method of apm-jdk-threadpool-plugin.
 
 All issues and pull requests are 
[here](https://github.com/apache/skywalking/milestone/213?closed=1)
 
diff --git 
a/apm-sniffer/bootstrap-plugins/jdk-threadpool-plugin/src/main/java/org/apache/skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java
 
b/apm-sniffer/bootstrap-plugins/jdk-threadpool-plugin/src/main/java/org/apache/skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java
index 7239453074..c72c1424b5 100644
--- 
a/apm-sniffer/bootstrap-plugins/jdk-threadpool-plugin/src/main/java/org/apache/skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java
+++ 
b/apm-sniffer/bootstrap-plugins/jdk-threadpool-plugin/src/main/java/org/apache/skywalking/apm/plugin/AbstractThreadingPoolInterceptor.java
@@ -63,6 +63,10 @@ public abstract class AbstractThreadingPoolInterceptor 
implements InstanceMethod
 
 @Override
 public void handleMethodException(EnhancedInstance objInst, Method method, 
Object[] allArguments, Class[] argumentsTypes, Throwable t) {
+if (!ContextManager.isActive()) {
+return;
+}
+
 ContextManager.activeSpan().log(t);
 }
 }