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
parent cf20d046
......@@ -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(
mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()),
handle.getTag() <= Opcodes.H_PUTSTATIC
? mapDesc(handle.getDesc())
: mapMethodDesc(handle.getDesc()),
? mapFieldName(handle.getOwner(), handle.getName(), handle.getDesc())
: mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()),
isFieldHandle ? mapDesc(handle.getDesc()) : mapMethodDesc(handle.getDesc()),
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());
public void testInvokeDynamicInsn_field() {
ClassNode classNode = new ClassNode();
ClassRemapper classRemapper =
new ClassRemapper(
/* latest api */ Opcodes.ASM9,
new Remapper() {
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);
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. */
Supports Markdown
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