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 9002727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:36:34+00:00 2026-06-16T00:36:34+00:00

I am trying to get the values of a Java program’s method’s parameters. I

  • 0

I am trying to get the values of a Java program’s method’s parameters.
I am using ASM to instrument the bytecode and getting these values.
However, I’m running into some troubles.

Here is the visitCode() method used to instrument the code.
What it is doing is :

  1. Create an empty array to store the collected parameters.
  2. For each parameter, load its value into the array.
  3. Send this array to my agent’s OnMethodEntry method (which where the values will be used).

.

@Override
public void visitCode() {
    int paramLength = paramTypes.length;

    // Create array with length equal to number of parameters
    mv.visitIntInsn(Opcodes.BIPUSH, paramLength);
    mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
    mv.visitVarInsn(Opcodes.ASTORE, paramLength);

    // Fill the created array with method parameters
    int i = 0;
    for (Type tp : paramTypes) {
        mv.visitVarInsn(Opcodes.ALOAD, paramLength);
        mv.visitIntInsn(Opcodes.BIPUSH, i);

        if (tp.equals(Type.BOOLEAN_TYPE) || tp.equals(Type.BYTE_TYPE) || tp.equals(Type.CHAR_TYPE) || tp.equals(Type.SHORT_TYPE) || tp.equals(Type.INT_TYPE))
            mv.visitVarInsn(Opcodes.ILOAD, i);
        else if (tp.equals(Type.LONG_TYPE)) {
            mv.visitVarInsn(Opcodes.LLOAD, i);
            i++;
        }
        else if (tp.equals(Type.FLOAT_TYPE))
            mv.visitVarInsn(Opcodes.FLOAD, i);
        else if (tp.equals(Type.DOUBLE_TYPE)) {
            mv.visitVarInsn(Opcodes.DLOAD, i);
            i++;
        }
        else
            mv.visitVarInsn(Opcodes.ALOAD, i);

        mv.visitInsn(Opcodes.AASTORE);
        i++;
    }

    // Load id, class name and method name
    this.visitLdcInsn(new Integer(this.methodID));
    this.visitLdcInsn(this.className);
    this.visitLdcInsn(this.methodName);

    // Load the array of parameters that we created
    this.visitVarInsn(Opcodes.ALOAD, paramLength);

    mv.visitMethodInsn(Opcodes.INVOKESTATIC,
            "jalen/MethodStats",
            "onMethodEntry",
            "(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V");
    super.visitCode();
}

However, this is not working when apparently the method have more than one parameter.

The class file obtained shows things like this :

static void moveDisk(char arg0, char arg1, PrintStream arg2) {
Object[] arrayOfObject = new Object[3]; arrayOfObject[0] = ???; arrayOfObject[1] = ???;
Object localObject;
arrayOfObject[2] = localObject; MethodStats.onMethodEntry(5, "hanoi/TowersOfHanoi", "moveDisk", arrayOfObject);

Where 2 local objects are created instead of loading the parameters.

The bytecode doesn’t show anything weird :

static void moveDisk(char, char, java.io.PrintStream);
Code:
   0: bipush        3
   2: anewarray     #4                  // class java/lang/Object
   5: astore_3      
   6: aload_3       
   7: bipush        0
   9: iload_0       
  10: aastore       
  11: aload_3       
  12: bipush        1
  14: iload_1       
  15: aastore       
  16: aload_3       
  17: bipush        2
  19: aload_2       
  20: aastore       
  21: ldc           #118                // int 5
  23: ldc           #12                 // String hanoi/TowersOfHanoi
  25: ldc           #119                // String moveDisk
  27: aload_3       
  28: invokestatic  #19                 // Method jalen/MethodStats.onMethodEntry:(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V

And finally, the error showed is (when using -noverify):

param: [Ljava.lang.String;@420e54f3
Exception in thread "Jalen Agent" java.lang.NullPointerException
at hanoi.TowersOfHanoi.solveHanoi(TowersOfHanoi.java)
at hanoi.TowersOfHanoi.main(TowersOfHanoi.java:29)

Otherwise, it is:

Exception in thread "Jalen Agent" java.lang.VerifyError: (class: hanoi/TowersOfHanoi, method: moveDisk signature: (CCLjava/io/PrintStream;)V) Expecting to find object/array on stack
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
    at java.lang.Class.getMethod0(Class.java:2685)
    at java.lang.Class.getMethod(Class.java:1620)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:492)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:484)

Normally, this should rather work as I am just loading information from the stack frame.
I tried also to check static & non static methods (as of the stack explained here : http://www.artima.com/insidejvm/ed2/jvm8.html), but still with no success.

Any idea on why this is happening, or possibly an idea of a solution ?

Thanks 🙂

EDIT:

It is now working when boxing up primitive types (thanks to suggestions by int3 below 🙂 ). Here is the working code of visitCode() method :

@Override
public void visitCode() {
    int paramLength = paramTypes.length;

    // Create array with length equal to number of parameters
    mv.visitIntInsn(Opcodes.BIPUSH, paramLength);
    mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
    mv.visitVarInsn(Opcodes.ASTORE, paramLength);

    // Fill the created array with method parameters
    int i = 0;
    for (Type tp : paramTypes) {
        mv.visitVarInsn(Opcodes.ALOAD, paramLength);
        mv.visitIntInsn(Opcodes.BIPUSH, i);

        if (tp.equals(Type.BOOLEAN_TYPE)) {
            mv.visitVarInsn(Opcodes.ILOAD, i);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;");
        }
        else if (tp.equals(Type.BYTE_TYPE)) {
            mv.visitVarInsn(Opcodes.ILOAD, i);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;");
        }
        else if (tp.equals(Type.CHAR_TYPE)) {
            mv.visitVarInsn(Opcodes.ILOAD, i);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;");
        }
        else if (tp.equals(Type.SHORT_TYPE)) {
            mv.visitVarInsn(Opcodes.ILOAD, i);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;");
        }
        else if (tp.equals(Type.INT_TYPE)) {
            mv.visitVarInsn(Opcodes.ILOAD, i);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
        }
        else if (tp.equals(Type.LONG_TYPE)) {
            mv.visitVarInsn(Opcodes.LLOAD, i);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
            i++;
        }
        else if (tp.equals(Type.FLOAT_TYPE)) {
            mv.visitVarInsn(Opcodes.FLOAD, i);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;");
        }
        else if (tp.equals(Type.DOUBLE_TYPE)) {
            mv.visitVarInsn(Opcodes.DLOAD, i);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;");
            i++;
        }
        else
            mv.visitVarInsn(Opcodes.ALOAD, i);

        mv.visitInsn(Opcodes.AASTORE);
        i++;
    }

    // Load id, class name and method name
    this.visitLdcInsn(new Integer(this.methodID));
    this.visitLdcInsn(this.className);
    this.visitLdcInsn(this.methodName);

    // Load the array of parameters that we created
    this.visitVarInsn(Opcodes.ALOAD, paramLength);

    mv.visitMethodInsn(Opcodes.INVOKESTATIC,
            "jalen/MethodStats",
            "onMethodEntry",
            "(ILjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V");
    super.visitCode();
}
  • 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-16T00:36:35+00:00Added an answer on June 16, 2026 at 12:36 am

    You are using aastore to store a char into an object array, which is a type error. aastore should only be used to store objects and arrays, which is probably why the error says ‘expected object/array on stack’. Characters should be stored in a char array using castore. However, since you want this to work for arbitrary signatures, you’ll probably want to box up the primitive types into objects which you can then use aastore upon — e.g. char should be boxed up in a java.lang.Character object.

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

Sidebar

Related Questions

I am making a Java/HTML program using Seam. I am trying to get an
I'm trying to get the returned value from a java method, but it returns
I am trying to get double values from file using fscanf function. I am
Mac OSX Netbeans JAVA Goal: BlackJack program... Im trying to get an imageIcon of
I'm trying to get to grips with the visitor method in Java. I'm trying
I'm trying to get command line input into a running java program that I
I am trying to get all the column values from a Table using JDBC.
I had been trying to get the tag name and its value in java
I'm trying to get values from nsdata class and doesn't work. here is my
I am trying to get values from a data set. My function has to

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.