Skip to content

Commit

Permalink
Upgrade to bytebuddy 1.16.1 and remove indy typeerasure workaround (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz authored Jan 20, 2025
1 parent b00858f commit 5d6ebba
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 223 deletions.
2 changes: 1 addition & 1 deletion conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies {
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.7.2")
implementation("org.spdx:spdx-gradle-plugin:0.8.0")
// When updating, also update dependencyManagement/build.gradle.kts
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.15.11")
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.16.1")
implementation("gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.6")
implementation("me.champeau.jmh:jmh-gradle-plugin:0.7.2")
implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.1.0")
Expand Down
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ val DEPENDENCY_BOMS = listOf(
val autoServiceVersion = "1.1.1"
val autoValueVersion = "1.11.0"
val errorProneVersion = "2.36.0"
val byteBuddyVersion = "1.15.11"
val byteBuddyVersion = "1.16.1"
val asmVersion = "9.7.1"
val jmhVersion = "1.37"
val mockitoVersion = "4.11.0"
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ configurations.named("compileOnly") {
extendsFrom(bbGradlePlugin)
}

val byteBuddyVersion = "1.15.11"
val byteBuddyVersion = "1.16.1"
val aetherVersion = "1.1.0"

dependencies {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import net.bytebuddy.matcher.ElementMatchers;

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

@Override
public Advice.PostProcessor make(MethodDescription.InDefinedShape adviceMethod, boolean exit) {
return delegate.make(forceDynamicTyping(adviceMethod), exit);
public Advice.PostProcessor make(
List<? extends AnnotationDescription> methodAnnotations,
TypeDescription returnType,
boolean exit) {
return delegate.make(forceDynamicTyping(methodAnnotations), returnType, exit);
}

// Visible for testing
static MethodDescription.InDefinedShape forceDynamicTyping(
MethodDescription.InDefinedShape adviceMethod) {
return new MethodDescription.Latent(
adviceMethod.getDeclaringType(),
adviceMethod.getInternalName(),
adviceMethod.getModifiers(),
adviceMethod.getTypeVariables().asTokenList(ElementMatchers.none()),
adviceMethod.getReturnType(),
adviceMethod.getParameters().asTokenList(ElementMatchers.none()),
adviceMethod.getExceptionTypes(),
forceDynamicTyping(adviceMethod.getDeclaredAnnotations()),
adviceMethod.getDefaultValue(),
adviceMethod.getReceiverType());
}

private static List<? extends AnnotationDescription> forceDynamicTyping(
static List<? extends AnnotationDescription> forceDynamicTyping(
List<? extends AnnotationDescription> declaredAnnotations) {
return declaredAnnotations.stream()
.map(ForceDynamicallyTypedAssignReturnedFactory::forceDynamicTyping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.logging.Logger;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.utility.JavaConstant;

/**
Expand Down Expand Up @@ -229,19 +227,10 @@ static Advice.BootstrapArgumentResolver.Factory getAdviceBootstrapArguments(
Arrays.asList(
JavaConstant.Simple.ofLoaded(BOOTSTRAP_KIND_ADVICE),
JavaConstant.Simple.ofLoaded(moduleName),
JavaConstant.Simple.ofLoaded(getOriginalSignature(adviceMethod)),
JavaConstant.Simple.ofLoaded(adviceMethod.getDescriptor()),
JavaConstant.Simple.ofLoaded(adviceMethod.getDeclaringType().getName()));
}

private static String getOriginalSignature(MethodDescription.InDefinedShape adviceMethod) {
for (AnnotationDescription an : adviceMethod.getDeclaredAnnotations()) {
if (OriginalDescriptor.class.getName().equals(an.getAnnotationType().getName())) {
return (String) an.getValue("value").resolve();
}
}
throw new IllegalStateException("OriginalSignature annotation is not present!");
}

private static ConstantCallSite bootstrapProxyMethod(
MethodHandles.Lookup lookup,
String proxyMethodName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.ClassFileLocator.Resolution;
import net.bytebuddy.matcher.ElementMatcher;

public final class IndyTypeTransformerImpl implements TypeTransformer {

// path (with trailing slash) to dump transformed advice class to
private static final String DUMP_PATH = null;
private final Advice.WithCustomMapping adviceMapping;
Expand All @@ -35,7 +37,8 @@ public IndyTypeTransformerImpl(
new Advice.AssignReturned.Factory().withSuppressed(Throwable.class)))
.bootstrap(
IndyBootstrap.getIndyBootstrapMethod(),
IndyBootstrap.getAdviceBootstrapArguments(instrumentationModule));
IndyBootstrap.getAdviceBootstrapArguments(instrumentationModule),
TypeDescription.Generic.Visitor.Generalizing.INSTANCE);
}

@Override
Expand Down Expand Up @@ -106,7 +109,6 @@ public byte[] resolve() {
} else {
result = bytes;
}
result = AdviceSignatureEraser.transform(result);
return result;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

import java.util.List;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
Expand Down Expand Up @@ -40,9 +41,10 @@ public void checkTypingMadeDynamic() {

ClassLoader cl = ForceDynamicallyTypedAssignReturnedFactoryTest.class.getClassLoader();

MethodDescription modified =
ForceDynamicallyTypedAssignReturnedFactory.forceDynamicTyping(original);
assertThat(modified.getDeclaredAnnotations())
List<? extends AnnotationDescription> modifiedAnnotations =
ForceDynamicallyTypedAssignReturnedFactory.forceDynamicTyping(
original.getDeclaredAnnotations());
assertThat(modifiedAnnotations)
.hasSize(7)
.anySatisfy(
toFields -> {
Expand Down
Loading

0 comments on commit 5d6ebba

Please sign in to comment.