Closed zzhlhc closed 7 months ago
Can you show your imports? I wonder if you imported the Advice version.
Sure, DispatcherDelegation's imports :
import net.bytebuddy.implementation.bind.annotation.FieldValue;
import net.bytebuddy.implementation.bind.annotation.This;
import okhttp3.Dispatcher;
import okhttp3.internal.connection.RealCall;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Field;
AgentMain's imports:
import javassist.ClassClassPath;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import net.bytebuddy.implementation.MethodDelegation;
import okhttp3.Dispatcher;
import okhttp3.internal.connection.RealCall;
import java.lang.instrument.ClassDefinition;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
import static net.bytebuddy.matcher.ElementMatchers.named;
byte-buddy's version:
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.11.22</version>
</dependency>
Solved, from your reply I realized that it might be a problem with the method parameters, deleted the executorService
below, and succeeded
public class DispatcherDelegation {
public static Boolean promoteAndExecute(@This Dispatcher dispatcher
, @FieldValue("executorService") ExecutorService executorService)
}
The executorService
in Dispatcher.kt
:
private var executorServiceOrNull: ExecutorService? = null
@get:Synchronized
@get:JvmName("executorService") val executorService: ExecutorService
get() {
if (executorServiceOrNull == null) {
executorServiceOrNull = ThreadPoolExecutor(0, Int.MAX_VALUE, 60, TimeUnit.SECONDS,
SynchronousQueue(), threadFactory("$okHttpName Dispatcher", false))
}
return executorServiceOrNull!!
}
I'm new to both byte-buddy and kotlin, anyway the problem is solved, thanks!!
I think the field is executorServiceOrNull, the other one is the method. so you'd use rhe first as field name.
Sorry for asking such a simple question, but I really couldn't find the relevant answer.
Below is my current code:
Error is:
How can I solve this problem? thank you very much! orz...