Skip to content

Commit 5d6ebba

Browse files
authored
Upgrade to bytebuddy 1.16.1 and remove indy typeerasure workaround (#13071)
1 parent b00858f commit 5d6ebba

File tree

12 files changed

+90
-223
lines changed

12 files changed

+90
-223
lines changed

conventions/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dependencies {
6464
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.7.2")
6565
implementation("org.spdx:spdx-gradle-plugin:0.8.0")
6666
// When updating, also update dependencyManagement/build.gradle.kts
67-
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.15.11")
67+
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.16.1")
6868
implementation("gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.6")
6969
implementation("me.champeau.jmh:jmh-gradle-plugin:0.7.2")
7070
implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.1.0")

dependencyManagement/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ val DEPENDENCY_BOMS = listOf(
4141
val autoServiceVersion = "1.1.1"
4242
val autoValueVersion = "1.11.0"
4343
val errorProneVersion = "2.36.0"
44-
val byteBuddyVersion = "1.15.11"
44+
val byteBuddyVersion = "1.16.1"
4545
val asmVersion = "9.7.1"
4646
val jmhVersion = "1.37"
4747
val mockitoVersion = "4.11.0"

gradle-plugins/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ configurations.named("compileOnly") {
2525
extendsFrom(bbGradlePlugin)
2626
}
2727

28-
val byteBuddyVersion = "1.15.11"
28+
val byteBuddyVersion = "1.16.1"
2929
val aetherVersion = "1.1.0"
3030

3131
dependencies {

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/AdviceSignatureEraser.java

-106
This file was deleted.

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/ForceDynamicallyTypedAssignReturnedFactory.java

+6-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import net.bytebuddy.description.method.MethodDescription;
1919
import net.bytebuddy.description.type.TypeDescription;
2020
import net.bytebuddy.implementation.bytecode.assign.Assigner;
21-
import net.bytebuddy.matcher.ElementMatchers;
2221

2322
/**
2423
* This factory is designed to wrap around {@link Advice.PostProcessor.Factory} and ensures that
@@ -53,27 +52,15 @@ public ForceDynamicallyTypedAssignReturnedFactory(Advice.PostProcessor.Factory d
5352
}
5453

5554
@Override
56-
public Advice.PostProcessor make(MethodDescription.InDefinedShape adviceMethod, boolean exit) {
57-
return delegate.make(forceDynamicTyping(adviceMethod), exit);
55+
public Advice.PostProcessor make(
56+
List<? extends AnnotationDescription> methodAnnotations,
57+
TypeDescription returnType,
58+
boolean exit) {
59+
return delegate.make(forceDynamicTyping(methodAnnotations), returnType, exit);
5860
}
5961

6062
// Visible for testing
61-
static MethodDescription.InDefinedShape forceDynamicTyping(
62-
MethodDescription.InDefinedShape adviceMethod) {
63-
return new MethodDescription.Latent(
64-
adviceMethod.getDeclaringType(),
65-
adviceMethod.getInternalName(),
66-
adviceMethod.getModifiers(),
67-
adviceMethod.getTypeVariables().asTokenList(ElementMatchers.none()),
68-
adviceMethod.getReturnType(),
69-
adviceMethod.getParameters().asTokenList(ElementMatchers.none()),
70-
adviceMethod.getExceptionTypes(),
71-
forceDynamicTyping(adviceMethod.getDeclaredAnnotations()),
72-
adviceMethod.getDefaultValue(),
73-
adviceMethod.getReceiverType());
74-
}
75-
76-
private static List<? extends AnnotationDescription> forceDynamicTyping(
63+
static List<? extends AnnotationDescription> forceDynamicTyping(
7764
List<? extends AnnotationDescription> declaredAnnotations) {
7865
return declaredAnnotations.stream()
7966
.map(ForceDynamicallyTypedAssignReturnedFactory::forceDynamicTyping)

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyBootstrap.java

+1-12
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import java.util.logging.Logger;
2121
import javax.annotation.Nullable;
2222
import net.bytebuddy.asm.Advice;
23-
import net.bytebuddy.description.annotation.AnnotationDescription;
24-
import net.bytebuddy.description.method.MethodDescription;
2523
import net.bytebuddy.utility.JavaConstant;
2624

2725
/**
@@ -229,19 +227,10 @@ static Advice.BootstrapArgumentResolver.Factory getAdviceBootstrapArguments(
229227
Arrays.asList(
230228
JavaConstant.Simple.ofLoaded(BOOTSTRAP_KIND_ADVICE),
231229
JavaConstant.Simple.ofLoaded(moduleName),
232-
JavaConstant.Simple.ofLoaded(getOriginalSignature(adviceMethod)),
230+
JavaConstant.Simple.ofLoaded(adviceMethod.getDescriptor()),
233231
JavaConstant.Simple.ofLoaded(adviceMethod.getDeclaringType().getName()));
234232
}
235233

236-
private static String getOriginalSignature(MethodDescription.InDefinedShape adviceMethod) {
237-
for (AnnotationDescription an : adviceMethod.getDeclaredAnnotations()) {
238-
if (OriginalDescriptor.class.getName().equals(an.getAnnotationType().getName())) {
239-
return (String) an.getValue("value").resolve();
240-
}
241-
}
242-
throw new IllegalStateException("OriginalSignature annotation is not present!");
243-
}
244-
245234
private static ConstantCallSite bootstrapProxyMethod(
246235
MethodHandles.Lookup lookup,
247236
String proxyMethodName,

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/IndyTypeTransformerImpl.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import net.bytebuddy.agent.builder.AgentBuilder;
1414
import net.bytebuddy.asm.Advice;
1515
import net.bytebuddy.description.method.MethodDescription;
16+
import net.bytebuddy.description.type.TypeDescription;
1617
import net.bytebuddy.dynamic.ClassFileLocator;
1718
import net.bytebuddy.dynamic.ClassFileLocator.Resolution;
1819
import net.bytebuddy.matcher.ElementMatcher;
1920

2021
public final class IndyTypeTransformerImpl implements TypeTransformer {
22+
2123
// path (with trailing slash) to dump transformed advice class to
2224
private static final String DUMP_PATH = null;
2325
private final Advice.WithCustomMapping adviceMapping;
@@ -35,7 +37,8 @@ public IndyTypeTransformerImpl(
3537
new Advice.AssignReturned.Factory().withSuppressed(Throwable.class)))
3638
.bootstrap(
3739
IndyBootstrap.getIndyBootstrapMethod(),
38-
IndyBootstrap.getAdviceBootstrapArguments(instrumentationModule));
40+
IndyBootstrap.getAdviceBootstrapArguments(instrumentationModule),
41+
TypeDescription.Generic.Visitor.Generalizing.INSTANCE);
3942
}
4043

4144
@Override
@@ -106,7 +109,6 @@ public byte[] resolve() {
106109
} else {
107110
result = bytes;
108111
}
109-
result = AdviceSignatureEraser.transform(result);
110112
return result;
111113
}
112114
}

javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/OriginalDescriptor.java

-10
This file was deleted.

javaagent-tooling/src/test/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/ForceDynamicallyTypedAssignReturnedFactoryTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

10+
import java.util.List;
1011
import net.bytebuddy.asm.Advice;
1112
import net.bytebuddy.asm.Advice.AssignReturned;
1213
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
@@ -40,9 +41,10 @@ public void checkTypingMadeDynamic() {
4041

4142
ClassLoader cl = ForceDynamicallyTypedAssignReturnedFactoryTest.class.getClassLoader();
4243

43-
MethodDescription modified =
44-
ForceDynamicallyTypedAssignReturnedFactory.forceDynamicTyping(original);
45-
assertThat(modified.getDeclaredAnnotations())
44+
List<? extends AnnotationDescription> modifiedAnnotations =
45+
ForceDynamicallyTypedAssignReturnedFactory.forceDynamicTyping(
46+
original.getDeclaredAnnotations());
47+
assertThat(modifiedAnnotations)
4648
.hasSize(7)
4749
.anySatisfy(
4850
toFields -> {

0 commit comments

Comments
 (0)