Unverified Commit 2a70d3a5 authored by Jamie Mansfield's avatar Jamie Mansfield
Browse files

Remap invokedynamic field handles properly

There was already handling for the descriptors, this covers the name
too.
parent cf20d046
Pipeline #15892 passed with stage
in 4 minutes and 1 second
......@@ -160,13 +160,15 @@ public abstract class Remapper {
}
if (value instanceof Handle) {
Handle handle = (Handle) value;
boolean isFieldHandle = handle.getTag() <= Opcodes.H_PUTSTATIC;
return new Handle(
handle.getTag(),
mapType(handle.getOwner()),
mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()),
handle.getTag() <= Opcodes.H_PUTSTATIC
? mapDesc(handle.getDesc())
: mapMethodDesc(handle.getDesc()),
isFieldHandle
? mapFieldName(handle.getOwner(), handle.getName(), handle.getDesc())
: mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()),
isFieldHandle ? mapDesc(handle.getDesc()) : mapMethodDesc(handle.getDesc()),
handle.isInterface());
}
if (value instanceof ConstantDynamic) {
......
......@@ -50,6 +50,7 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.test.AsmTest;
import org.objectweb.asm.test.ClassFile;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.util.CheckMethodAdapter;
......@@ -209,6 +210,38 @@ public class ClassRemapperTest extends AsmTest {
assertEquals("()Ljava/lang/Integer;", constantDynamic.getBootstrapMethod().getDesc());
}
@Test
public void testInvokeDynamicInsn_field() {
ClassNode classNode = new ClassNode();
ClassRemapper classRemapper =
new ClassRemapper(
/* latest api */ Opcodes.ASM9,
classNode,
new Remapper() {
@Override
public String mapFieldName(
final String owner, final String name, final String descriptor) {
if ("a".equals(name)) {
return "demo";
}
return name;
}
});
classRemapper.visit(Opcodes.V11, Opcodes.ACC_PUBLIC, "C", null, "java/lang/Object", null);
MethodVisitor methodVisitor =
classRemapper.visitMethod(Opcodes.ACC_PUBLIC, "hello", "()V", null, null);
methodVisitor.visitCode();
methodVisitor.visitInvokeDynamicInsn(
"foo",
"()Ljava/lang/String;",
new Handle(Opcodes.H_GETFIELD, "pkg/B", "a", "Ljava/lang/String;", false));
InvokeDynamicInsnNode invokeDynamic =
(InvokeDynamicInsnNode) classNode.methods.get(0).instructions.get(0);
assertEquals("demo", invokeDynamic.bsm.getName());
}
/** Tests that classes transformed with a ClassRemapper can be loaded and instantiated. */
@ParameterizedTest
@MethodSource(ALL_CLASSES_AND_ALL_APIS)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment