From c719d4cae4101befc3caebeb864f499527f987af Mon Sep 17 00:00:00 2001 From: HaojunRen <1394997@qq.com> Date: Mon, 15 Jan 2024 18:35:38 +0800 Subject: [PATCH] Fix the error 'no method body' with reactor.core.publisher.Signal --- .../plugin/spring/async/SpringAsyncPlugin.java | 13 +++++++++---- .../plugin/thread/ThreadTransformCallback.java | 6 +++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/discovery-agent-starter/src/main/java/com/nepxion/discovery/agent/plugin/spring/async/SpringAsyncPlugin.java b/discovery-agent-starter/src/main/java/com/nepxion/discovery/agent/plugin/spring/async/SpringAsyncPlugin.java index 054675a..7222492 100644 --- a/discovery-agent-starter/src/main/java/com/nepxion/discovery/agent/plugin/spring/async/SpringAsyncPlugin.java +++ b/discovery-agent-starter/src/main/java/com/nepxion/discovery/agent/plugin/spring/async/SpringAsyncPlugin.java @@ -11,6 +11,7 @@ import javassist.CtClass; import javassist.CtMethod; +import javassist.Modifier; import java.security.ProtectionDomain; @@ -37,10 +38,14 @@ public byte[] doInTransform(ClassLoader classLoader, String className, Class try { ClassInfo classInfo = new ClassInfo(className, classfileBuffer, classLoader); CtClass ctClass = classInfo.getCtClass(); - CtMethod method = ctClass.getMethod("doSubmit", "(Ljava/util/concurrent/Callable;Lorg/springframework/core/task/AsyncTaskExecutor;Ljava/lang/Class;)Ljava/lang/Object;"); - if (null != method) { + if (ctClass.isInterface()) { + return null; + } + + CtMethod ctMethod = ctClass.getMethod("doSubmit", "(Ljava/util/concurrent/Callable;Lorg/springframework/core/task/AsyncTaskExecutor;Ljava/lang/Class;)Ljava/lang/Object;"); + if (null != ctMethod && !Modifier.isNative(ctMethod.getModifiers()) && !Modifier.isAbstract(ctMethod.getModifiers())) { StringBuffer sb = new StringBuffer(); - CtClass[] parameterTypes = method.getParameterTypes(); + CtClass[] parameterTypes = ctMethod.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { final String paramTypeName = parameterTypes[i].getName(); if (CALLABLE_CLASS_NAME.equals(paramTypeName)) { @@ -49,7 +54,7 @@ public byte[] doInTransform(ClassLoader classLoader, String className, Class } if (sb.length() > 0) { - method.insertBefore(sb.toString()); + ctMethod.insertBefore(sb.toString()); } } diff --git a/discovery-agent-starter/src/main/java/com/nepxion/discovery/agent/plugin/thread/ThreadTransformCallback.java b/discovery-agent-starter/src/main/java/com/nepxion/discovery/agent/plugin/thread/ThreadTransformCallback.java index a611960..af1d2fb 100644 --- a/discovery-agent-starter/src/main/java/com/nepxion/discovery/agent/plugin/thread/ThreadTransformCallback.java +++ b/discovery-agent-starter/src/main/java/com/nepxion/discovery/agent/plugin/thread/ThreadTransformCallback.java @@ -14,6 +14,7 @@ import javassist.CtConstructor; import javassist.CtField; import javassist.CtMethod; +import javassist.Modifier; import java.lang.reflect.Method; import java.security.ProtectionDomain; @@ -31,6 +32,9 @@ public byte[] doInTransform(ClassLoader classLoader, String className, Class try { ClassInfo classInfo = new ClassInfo(className, classfileBuffer, classLoader); CtClass ctClass = classInfo.getCtClass(); + if (ctClass.isInterface()) { + return null; + } addField(ctClass, AsyncContextAccessor.class); @@ -41,7 +45,7 @@ public byte[] doInTransform(ClassLoader classLoader, String className, Class String implMethodName = getImplMethodName(); CtMethod ctMethod = ctClass.getDeclaredMethod(implMethodName); - if (null != ctMethod) { + if (null != ctMethod && !Modifier.isNative(ctMethod.getModifiers()) && !Modifier.isAbstract(ctMethod.getModifiers())) { ctMethod.insertBefore(ThreadConstant.RUN_BEFORE_INTERCEPTOR); ctMethod.insertAfter(ThreadConstant.RUN_AFTER_INTERCEPTOR); }