This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git
The following commit(s) were added to refs/heads/main by this push:
new e08c4583a3 Exclude synthetic methods for WitnessMethod (#504)
e08c4583a3 is described below
commit e08c4583a33cbb9917883a6969b77a6da355d1ee
Author: Jiajing LU <[email protected]>
AuthorDate: Fri Apr 14 17:23:47 2023 +0800
Exclude synthetic methods for WitnessMethod (#504)
---
CHANGES.md | 1 +
.../apm/agent/core/plugin/WitnessMethod.java | 10 ++++++++--
.../apm/agent/core/plugin/witness/WitnessTest.java | 20 ++++++++++++++++++++
.../scenarios/shenyu-2.4.x-sofarpc-scenario/pom.xml | 8 +++++++-
4 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index f3ea698b8b..f910d6321e 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 d1b508695c..73c9379101 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<? super MethodDescription.InDefinedShape>
elementMatcher;
+ public WitnessMethod(String declaringClassName, ElementMatcher.Junction<?
super MethodDescription.InDefinedShape> 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 6a5a751e77..4eab65d4a8 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<Map<String, Object>> foo(List<Map<String, Object>> 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 8f0838e932..c0e9c5191f 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 @@
<type>pom</type>
<scope>import</scope>
</dependency>
+ <dependency>
+ <groupId>io.grpc</groupId>
+ <artifactId>grpc-bom</artifactId>
+ <version>1.28.1</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-gateway</artifactId>
@@ -103,7 +110,6 @@
</dependencies>
</dependencyManagement>
-
<build>
<finalName>shenyu-2.4.x-sofarpc-scenario</finalName>
<plugins>