3

I am using Java ASM to add a method to compiled class. During run time I am getting
below error, when the newly added method is invoked.

    ClassFormatError: Field "valueEquals" in class test/asm/Item has illegal signature "(Ljava/lang/Object;)Z"  

Below is the method which I expecting to add

    public boolean valueEquals(Object obj){  
        return ItemHelper.valueEquals(obj);  
    }  

Below is the asm code for this.

    String methodName = "valueEquals";  
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, methodName, "(Ljava/lang/Object;)Z", null, null);  
    mv.visitCode();  
    mv.visitVarInsn(ALOAD, 1);  
    mv.visitFieldInsn(INVOKESTATIC, "test/asm/ItemHelper", methodName, "(Ljava/lang/Object;)Z");  
    mv.visitInsn(IRETURN);  
    mv.visitMaxs(2, 1);  
    mv.visitEnd();  

Please can some one help me in identifying what I am doing wrong here. Your help is very much appreciated.

1 Answer 1

3

You need to use visitMethodInsn instead of visitFieldInsn, since you are calling a method, not accessing a field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.