Skip to content

Commit

Permalink
fix injected methods in interface statics/defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed May 23, 2024
1 parent c9cc916 commit 6069dec
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xyz.wagyourtail.downgradetest;

import java.util.function.Function;

public interface TestInterface {
String test5 = "test";

Expand All @@ -20,7 +22,22 @@ private void test() {
}

static void test3() {
System.out.println("test3");
System.out.println("test3" + 4);

Function<Long, IndexOutOfBoundsException> IOOBE = IndexOutOfBoundsException::new;
IOOBE.apply(0L);

switch (TestSwitch.TestEnum.A) {
case A:
System.out.println("A");
break;
case B:
System.out.println("B");
break;
case TestSwitch.TestEnum ignored:
System.out.println("ignored");
break;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static MethodInsnNode makeSwitchInternal(String holdingMethod, String des
for (MethodNode mnode : cnode.methods) {
if (mnode instanceof SwitchMethodNode smnode) {
if (smnode.types.equals(types)) {
return new MethodInsnNode(Opcodes.INVOKESTATIC, cnode.name, mnode.name, mnode.desc, false);
return new MethodInsnNode(Opcodes.INVOKESTATIC, cnode.name, mnode.name, mnode.desc, (cnode.access & Opcodes.ACC_INTERFACE) != 0);
}
if (mnode.name.equals("jvmdowngrader$switch$" + holdingMethod + "$" + i)) {
i++;
Expand Down Expand Up @@ -351,7 +351,7 @@ public static MethodInsnNode makeSwitchInternal(String holdingMethod, String des
smnode.visitMaxs(0, 0);
smnode.visitEnd();
cnode.methods.add(smnode);
return new MethodInsnNode(Opcodes.INVOKESTATIC, cnode.name, name, desc, false);
return new MethodInsnNode(Opcodes.INVOKESTATIC, cnode.name, name, desc, (cnode.access & Opcodes.ACC_INTERFACE) != 0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public static InsnList makeConcatInternal3(String mname, ClassNode node, String
node.name,
concatMethod.name,
concatMethod.desc,
false
(node.access & Opcodes.ACC_INTERFACE) != 0
));
return list;
}
Expand All @@ -480,7 +480,7 @@ public static InsnList makeConcatInternal3(String mname, ClassNode node, String
node.name,
method.name,
method.desc,
false
(node.access & Opcodes.ACC_INTERFACE) != 0
));
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,12 @@ public MethodNode stubMethods(MethodNode method, ClassNode owner, Set<ClassNode>
String newOwner = Type.getType(m.getDeclaringClass()).getInternalName();
String name = m.getName();
String desc = Type.getMethodDescriptor(m);
boolean intf = m.getDeclaringClass().isInterface();
if (!desc.equals(hStaticDesc.getDescriptor())) {
// create wrapper as desc should exactly match.
newOwner = owner.name;
desc = hStaticDesc.getDescriptor();
intf = (owner.access & Opcodes.ACC_INTERFACE) != 0;
MethodNode found = null;
int num = 0;
for (MethodNode mn : owner.methods) {
Expand Down Expand Up @@ -562,7 +564,7 @@ public MethodNode stubMethods(MethodNode method, ClassNode owner, Set<ClassNode>
newOwner,
name,
desc,
false
intf
);
}
} else {
Expand All @@ -576,6 +578,7 @@ public MethodNode stubMethods(MethodNode method, ClassNode owner, Set<ClassNode>

String name;
String desc = Type.getMethodDescriptor(returnType, arguments);
boolean intf = (owner.access & Opcodes.ACC_INTERFACE) != 0;

MethodNode found = null;
int num = 0;
Expand Down Expand Up @@ -639,7 +642,7 @@ public MethodNode stubMethods(MethodNode method, ClassNode owner, Set<ClassNode>
owner.name,
name,
desc,
false
intf
);

}
Expand Down

0 comments on commit 6069dec

Please sign in to comment.