diff --git a/CHANGES.md b/CHANGES.md index f3ea698b8..f910d6321 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ Release Notes. 8.16.0 ------------------ +* Exclude `synthetic` methods for the WitnessMethod mechanism #### Documentation diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/WitnessMethod.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/WitnessMethod.java index d1b508695..73c937910 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/WitnessMethod.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/WitnessMethod.java @@ -18,17 +18,19 @@ package org.apache.skywalking.apm.agent.core.plugin; +import com.google.common.base.Preconditions; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.ToString; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; +import static net.bytebuddy.matcher.ElementMatchers.isSynthetic; +import static net.bytebuddy.matcher.ElementMatchers.not; + /** * Witness Method for plugin activation */ @ToString -@RequiredArgsConstructor public class WitnessMethod { /** @@ -42,4 +44,8 @@ public class WitnessMethod { @Getter private final ElementMatcher elementMatcher; + public WitnessMethod(String declaringClassName, ElementMatcher.Junction elementMatcher) { + this.declaringClassName = declaringClassName; + this.elementMatcher = Preconditions.checkNotNull(elementMatcher).and(not(isSynthetic())); + } } diff --git a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/plugin/witness/WitnessTest.java b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/plugin/witness/WitnessTest.java index 6a5a751e7..4eab65d4a 100644 --- a/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/plugin/witness/WitnessTest.java +++ b/apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/plugin/witness/WitnessTest.java @@ -21,6 +21,7 @@ package org.apache.skywalking.apm.agent.core.plugin.witness; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatchers; +import net.bytebuddy.pool.TypePool; import org.apache.skywalking.apm.agent.core.plugin.WitnessFinder; import org.apache.skywalking.apm.agent.core.plugin.WitnessMethod; import org.junit.Assert; @@ -60,8 +61,27 @@ public class WitnessTest { Assert.assertTrue(finder.exist(witnessMethod, this.getClass().getClassLoader())); } + @Test + public void testSyntheticMethods() { + // public void org.apache.skywalking.apm.agent.core.plugin.witness.WitnessTest$Child.foo() + Assert.assertEquals(Child.class.getDeclaredMethods().length, 1); + // with an additional synthetic constructor + Assert.assertEquals(TypePool.Default.ofSystemLoader().describe(className + "$Child").resolve().getDeclaredMethods().size(), 2); + WitnessMethod witnessMethod = new WitnessMethod(className + "$Child", ElementMatchers.named("foo")); + Assert.assertTrue(finder.exist(className + "$Child", this.getClass().getClassLoader())); + Assert.assertFalse(finder.exist(witnessMethod, this.getClass().getClassLoader())); + } + public List> foo(List> param, String s) { return null; } + public static class Child extends Base { + + } + + static class Base { + public void foo() { + } + } } diff --git a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml index 8f0838e93..c0e9c5191 100644 --- a/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml +++ b/test/plugin/scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml @@ -63,6 +63,13 @@ pom import + + io.grpc + grpc-bom + 1.28.1 + pom + import + org.apache.shenyu shenyu-spring-boot-starter-gateway @@ -103,7 +110,6 @@ - shenyu-2.4.x-sofarpc-scenario