Exclude synthetic methods for WitnessMethod (#504)
This commit is contained in:
parent
7a6334d2b5
commit
e08c4583a3
|
|
@ -5,6 +5,7 @@ Release Notes.
|
|||
8.16.0
|
||||
------------------
|
||||
|
||||
* Exclude `synthetic` methods for the WitnessMethod mechanism
|
||||
|
||||
#### Documentation
|
||||
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue