ingokegel / jclasslib

jclasslib bytecode editor is a tool that visualizes all aspects of compiled Java class files and the contained bytecode.
Other
2.66k stars 405 forks source link

A issue about LocalVariableTable #47

Closed seedskys closed 3 years ago

seedskys commented 3 years ago

When I used the Jclasslib plugin for IDEA, I found that there was a problem with the location of the variables in the LocalVariableTable.

eg: demo: `public class Test{

public static void main(String[] a){
}
public void test1(int a){
    System.out.println(this);
    if(a==0){
        int c=0;
        System.out.println(c);
    }
}

} ` result:

in jlcasslib:

image

Decompiled to bytecode:

public void test1(int); descriptor: (I)V flags: ACC_PUBLIC Code: stack=2, locals=3, args_size=2 0: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream; 3: aload_0 4: invokevirtual #6 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V 7: iload_1 8: ifne 20 11: iconst_0 12: istore_2 13: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream; 16: iload_2 17: invokevirtual #7 // Method java/io/PrintStream.println:(I)V 20: return LineNumberTable: line 17: 0 line 18: 7 line 19: 11 line 20: 13 line 22: 20 StackMapTable: number_of_entries = 1 frame_type = 20 / same / }

As shown above, the first variable in the method's LocalVariableTable should be THIS instead of C

ingokegel commented 3 years ago

The logical variable index is in the 4th column, not in the first column. The first column is the physical index in the class file.