raphw / byte-buddy

Runtime code generation for the Java virtual machine.
https://bytebuddy.net
Apache License 2.0
6.3k stars 808 forks source link

Unable to proxy ThreadPoolExecutor #1729

Open ZShUn opened 2 days ago

ZShUn commented 2 days ago

What configuration options do I need to add to the proxy ThreadPoolExecutor?

new AgentBuilder.Default()
                .ignore(
                        nameStartsWith("net.bytebuddy.")
                                .or(nameStartsWith("org.slf4j."))
                                .or(nameStartsWith("org.groovy."))
                                .or(nameContains("javassist"))
                                .or(nameContains(".asm."))
                                .or(nameContains(".reflectasm."))
                                .or(nameStartsWith("sun.reflect"))
                                .or(ElementMatchers.isSynthetic()))
                .type(new CustomClassMatcher<>(classMatcherConfig, TypeDescription.ForLoadedType.of(Runnable.class)))
                .transform(transformer)
                .with(listener)
                .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
                .installOn(inst);

@RuntimeType
    public static Object intercept(@This Object obj, @AllArguments Object[] allArguments, @SuperCall Callable<?> callable, @Origin Method method) throws Exception {
        Object result = null;
        try {
            result = callable.call();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return result;
 }
1732458469230
raphw commented 21 hours ago

You would need to configure a different InjectionStrategy in your AgentBuilder. Typically one that uses Unsafe.