提交 a5d26103 编写于 作者: X Xin,Zhang 提交者: wu-sheng

Fix #1488: Fix NPE when the targetAop class is null (#1507)

上级 eed6fa18
...@@ -15,17 +15,15 @@ ...@@ -15,17 +15,15 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.skywalking.apm.plugin.spring.patch; package org.apache.skywalking.apm.plugin.spring.patch;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
/** /**
* {@link AopExpressionMatchInterceptor} check if the method is match the enhanced method * {@link AopExpressionMatchInterceptor} check if the method is match the enhanced method
...@@ -42,30 +40,33 @@ public class AopExpressionMatchInterceptor implements StaticMethodsAroundInterce ...@@ -42,30 +40,33 @@ public class AopExpressionMatchInterceptor implements StaticMethodsAroundInterce
} }
@Override @Override
public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, MethodInterceptResult result) { public void beforeMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
MethodInterceptResult result) {
} }
@Override @Override
public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, Object ret) { public Object afterMethod(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Method targetAopMethod = (Method) allArguments[1]; Object ret) {
Class<?> targetAopClass = (Class<?>) allArguments[2]; Method targetAopMethod = (Method)allArguments[1];
if (EnhancedInstance.class.isAssignableFrom(targetAopClass) && isEnhancedMethod(targetAopMethod)) { Class<?> targetAopClass = (Class<?>)allArguments[2];
if (targetAopClass != null && EnhancedInstance.class.isAssignableFrom(targetAopClass) && isEnhancedMethod(targetAopMethod)) {
return false; return false;
} }
return ret; return ret;
} }
@Override @Override
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes, Throwable t) { public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Throwable t) {
} }
private boolean isEnhancedMethod(Method targetMethod) { private boolean isEnhancedMethod(Method targetMethod) {
for (Method method : methods) { for (Method method : methods) {
if (method.getName().equals(targetMethod.getName()) if (method.getName().equals(targetMethod.getName())
&& method.getReturnType().equals(targetMethod.getReturnType()) && method.getReturnType().equals(targetMethod.getReturnType())
&& equalParamTypes(method.getParameterTypes(), targetMethod.getParameterTypes())) { && equalParamTypes(method.getParameterTypes(), targetMethod.getParameterTypes())) {
return true; return true;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册