Skip to content

Commit

Permalink
fix invokedynamic shouldProcess not using name/desc from Handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Feb 13, 2024
1 parent df4d091 commit 76bdee4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public interface FilteredMethodRewriteRule extends MethodRewriteRule, OwnableRewriteRule {

private static String transformExecutableName(final Executable executable) {
return executable instanceof Constructor<?> ? "<init>" : executable.getName();
return executable instanceof Constructor<?> ? StaticRewrite.CONSTRUCTOR_METHOD_NAME : executable.getName();
}

MethodMatcher methodMatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void visitMethodInsn(final int opcode, final String owner, final String n
@Override
public void visitInvokeDynamicInsn(final String name, final String descriptor, final Handle bootstrapMethodHandle, final Object... bootstrapMethodArguments) {
if (LAMBDA_METAFACTORY_OWNER.equals(bootstrapMethodHandle.getOwner()) && bootstrapMethodArguments.length > 1 && bootstrapMethodArguments[1] instanceof final Handle handle) {
if (MethodRewriteRule.this.shouldProcess(context, handle.getTag(), handle.getOwner(), name, descriptor, handle.isInterface())) {
if (MethodRewriteRule.this.shouldProcess(context, handle.getTag(), handle.getOwner(), handle.getName(), handle.getDesc(), handle.isInterface())) {
final @Nullable Rewrite rewrite = MethodRewriteRule.this.rewrite(context, true, handle.getTag(), handle.getOwner(), handle.getName(), methodDesc(handle.getDesc()), handle.isInterface());
if (rewrite != null) {
bootstrapMethodArguments[1] = rewrite.createHandle();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/io/papermc/asm/rules/method/StaticRewrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

public interface StaticRewrite extends FilteredMethodRewriteRule {

String CONSTRUCTOR_METHOD_NAME = "<init>";

ClassDesc staticRedirectOwner();

default MethodTypeDesc modifyMethodDescriptor(final MethodTypeDesc bytecodeDescriptor) {
Expand All @@ -39,7 +41,7 @@ default MethodRewriteRule.Rewrite rewrite(final ClassProcessingContext context,
if (isVirtual(opcode, invokeDynamic) || isInterface(opcode, invokeDynamic)) { // insert owner object as first param
descriptor = descriptor.insertParameterTypes(0, fromOwner(owner));
} else if (isSpecial(opcode, invokeDynamic)) {
if ("<init>".equals(name)) {
if (CONSTRUCTOR_METHOD_NAME.equals(name)) {
name = "create" + owner.substring(owner.lastIndexOf('/') + 1);
descriptor = descriptor.changeReturnType(fromOwner(owner));
return new RewriteConstructor(this.staticRedirectOwner(), owner, name, this.modifyMethodDescriptor(descriptor));
Expand All @@ -61,7 +63,7 @@ public void apply(final MethodVisitor delegate, final MethodNode context) {
boolean handled = false;
final Deque<String> typeStack = new ArrayDeque<>();
while (insn != null) {
if (insn.getOpcode() == Opcodes.INVOKESPECIAL && "<init>".equals(((MethodInsnNode) insn).name)) {
if (insn.getOpcode() == Opcodes.INVOKESPECIAL && CONSTRUCTOR_METHOD_NAME.equals(((MethodInsnNode) insn).name)) {
typeStack.push(((MethodInsnNode) insn).owner);
}
if (wasDup && insn.getOpcode() == Opcodes.NEW) {
Expand Down

0 comments on commit 76bdee4

Please sign in to comment.