Skip to content

Commit

Permalink
Fix NPE in handleMethodException method of apm-jdk-threadpool-plugin. (
Browse files Browse the repository at this point in the history
…#681) (#682)

Co-authored-by: forrestwang <[email protected]>
  • Loading branch information
ForrestWang123 and forrestwang authored Apr 19, 2024
1 parent ec30b5f commit 1a01047
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,11 @@
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;
}
Expand All @@ -63,10 +52,25 @@ public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allA

@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;
}
}

0 comments on commit 1a01047

Please sign in to comment.