Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:46:20+00:00 2026-06-13T23:46:20+00:00

I am having difficulties using the ASM byte code library to create proxy methods.

  • 0

I am having difficulties using the ASM byte code library to create proxy methods.

I wish to convert the following code:

public ReturnType doSomething( ParameterOne parameterOne, 
    ParameterTwo parameterTwo ){

    ReturnType returnType = new ReturnType();
    returnType.setDataOne( parameterOne.getDataOne() );
    returnType.setDataTwo( parameterTwo.getDataTwo() );
    return returnType;
}

to:

public ReturnType copyOff_doSomething( ParameterOne parameterOne, 
    ParameterTwo parameterTwo ){

    ReturnType returnType = new ReturnType();
    returnType.setDataOne( parameterOne.getDataOne() );
    returnType.setDataTwo( parameterTwo.getDataTwo() );
    return returnType;
}

public ReturnType doSomething( ParameterOne parameterOne, 
    ParameterTwo parameterTwo ){

    return copyOff_doSomething( parameterOne, parameterTwo );
}

To create the copyOff_doSomething() method I am using the following code:

public MethodVisitor visitMethod( int access, String name, String desc, 
    String signature, String[] exceptions ) {

    System.out.println(
        "access= " + access + ", name = " + name + ", desc = " +
                  desc + ", signature = " + signature );

    if ( name.equals( "doSomething" ) ){

        MethodVisitor methodVisitor =
            super.visitMethod( access, "copyOff_" + name, desc, 
                signature, exceptions );

        return methodVisitor;
    }
    else {
        return super.visitMethod( access, name, desc, signature, exceptions );
    }
}

The above code effectively removes the original doSomething() method and copies it to copyOff_doSomething() along with its body of code.

My problem occurs when I am generating the replacement doSomething() method:

@Override
public void visitEnd() {

    MethodVisitor mv = super.visitMethod( ACC_PUBLIC, "doSomething", 
        "(Lcom/javaspeak/classloader/tests/proxymethod/ParameterOne;" + 
        "Lcom/javaspeak/classloader/tests/proxymethod/ParameterTwo;)" + 
        "Lcom/javaspeak/classloader/tests/proxymethod/ReturnType;", 
            null, null );

    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel( l0 );
    mv.visitLineNumber( 18, l0 );
    mv.visitVarInsn( ALOAD, 0 );
    mv.visitVarInsn( ALOAD, 1 );
    mv.visitVarInsn( ALOAD, 2 );

    mv.visitMethodInsn( INVOKEVIRTUAL, 
        "com/javaspeak/classloader/tests/proxymethod/FinalMethod", 
           "copyOff_doSomething", 
               "(Lcom/javaspeak/classloader/tests/proxymethod/ParameterOne;" +        
               "Lcom/javaspeak/classloader/tests/proxymethod/ParameterTwo;)" + 
               "Lcom/javaspeak/classloader/tests/proxymethod/ReturnType;");

    mv.visitInsn( ARETURN );
    Label l1 = new Label();
    mv.visitLabel( l1 );

    mv.visitLocalVariable( "this", 
       "Lcom/javaspeak/classloader/tests/proxymethod/FinalMethod;", 
           null, l0, l1, 0 );

    mv.visitLocalVariable( "parameterOne", 
        "Lcom/javaspeak/classloader/tests/proxymethod/ParameterOne;", 
            null, l0, l1, 1 );

    mv.visitLocalVariable( "parameterTwo", 
        "Lcom/javaspeak/classloader/tests/proxymethod/ParameterTwo;", 
            null, l0, l1, 2 );

    mv.visitMaxs( 3, 3 );
    mv.visitEnd();
    super.visitEnd();
}

The problem is I get the following error:

java.lang.VerifyError: Bad type on operand stack in method 
com.javaspeak.classloader.tests.proxymethod.ProxyMethod.doSomething(
Lcom/javaspeak/classloader/tests/proxymethod/ParameterOne;
Lcom/javaspeak/classloader/tests/proxymethod/ParameterTwo;)
Lcom/javaspeak/classloader/tests/proxymethod/ReturnType; at offset 3

I do not know what the error means and how to fix the error. As mentioned above I used ASMfier to generate the code for the replacement doSomething() method.

My strategy was to use the visitMethod method to rename doSomething() to copyOff_doSomething() and then use the visitEnd() method to generate a new replacement doSomething() method from scratch that calls the copyOff_doSomething() method.

Perhaps ASM does not cater for my strategy and I should do it a different way?

Perhaps I need to modify the code that the ASMfier generated for the replacement doSomething() method. My understanding of the generated code is not that good.

I am using JDK 1.7 and ASM 4.0. I used ASMfier to see what ASM byte code instructions to use to generate the replacement doSomething() method.

If anyone knows ASM your help will be much appreciated?

Cheers

John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:46:23+00:00Added an answer on June 13, 2026 at 11:46 pm

    Most likely the owner parameter (hardcoded to com/javaspeak/classloader/tests/proxymethod/FinalMethod in your example) don’t match the actual type for this. So, your adapter should be using the name value from ClassVisitor.visit(..) call.

    Also see “Replace Method Body” section in my AOSD’07 paper “Using ASM framework to implement common bytecode transformation patterns”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am having difficulties using Url.Action method, please see my code below, what
I'm having difficulties understanding why the following line of code works in node.js: server.listen(12345,
I am having difficulties in retrieving 50 results from google. I'm using this: public
I am having difficulties using the ColorMatrixColorFilter to modify the color pixels in a
I'm having difficulties removing the lineStyle lines in JTrees using Netbeans. In a standalone
I am having difficulties in disabling href links through jquery. I am using this
I am using a AJAX gallery called jCarousel, and I am having some difficulties
I seem to be having difficulties using jQuery .animate() to animate an absolutely positioned
I'm having difficulties animating my custom layer property using Core Anmiation. My question is
i am having difficulties creating my own Zend_Auth_Adapter. i am using Doctrine 2 with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.