Re: Getting the local variables of a method

Matthew Wilson <[email protected]> Tue, 3 Nov 2009 09:32:07 +0000
Newsgroups gmane.comp.jakarta.bcel.user
Message-ID <[email protected]>
2009/11/2 MUTHURAMAN SWAMINADHAN <[email protected]>:
> I have been trying to get the local variables in a method but I don't see=
 anything returned. I am using the following snippet.
>
> LocalVariable lv[];
> LocalVariableTable lvt;
> lvt=3Dmt.getLocalVariableTable(); //mt is a method =A0object
> lv=3Dlvt.getLocalVariableTable();
>
> I don't get anything back in the lv array. Can anyone advise if this is t=
he correct approach or if there is a better approach?

The local variable table is an optional table in the class file.
Unless you compile with the debug option (which, by default, includes
the local variables, line numbers, and location of the original
source), it will be missing.  Try "javac -g" to compile.

See the Java VM specification for more details:

  http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.htm=
l#5956

You can also use javap to have a look at the local variable table (to
see if it is there in the file):

  javap -verbose MyClass

I hope that helps.

Kind regards,
Matthew