diff --git a/src/de/inetsoftware/classparser/Code.java b/src/de/inetsoftware/classparser/Code.java index 37458de..bc903e0 100644 --- a/src/de/inetsoftware/classparser/Code.java +++ b/src/de/inetsoftware/classparser/Code.java @@ -104,10 +104,12 @@ public class Code { } AttributeInfo data = attributes.get( "LocalVariableTable" ); if( data != null ) { - localVariableTable = new LocalVariableTable( maxLocals, constantPool ); - localVariableTable.read( data.getDataInputStream() ); + localVariableTable = new LocalVariableTable( maxLocals, constantPool, data.getDataInputStream() ); // we does not need any generics information // data = attributes.get( "LocalVariableTypeTable" ); + } else { + // return only the maxLocals + localVariableTable = new LocalVariableTable( maxLocals ); } return localVariableTable; } diff --git a/src/de/inetsoftware/classparser/LocalVariableTable.java b/src/de/inetsoftware/classparser/LocalVariableTable.java index fa4527d..74585ae 100644 --- a/src/de/inetsoftware/classparser/LocalVariableTable.java +++ b/src/de/inetsoftware/classparser/LocalVariableTable.java @@ -24,8 +24,6 @@ import java.io.IOException; */ public class LocalVariableTable { - private final ConstantPool constantPool; - private final int maxLocals; private LocalVariable[] table; @@ -33,26 +31,21 @@ public class LocalVariableTable { /** * Create a new instance of the code attribute "LocalVariableTable". * + * http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.13 + * http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#5956 + * @param maxLocals * the count of local variables in the memory * @param constantPool * Reference to the current ConstantPool - */ - LocalVariableTable( int maxLocals, ConstantPool constantPool ) { - this.maxLocals = maxLocals; - this.constantPool = constantPool; - } - - /** - * http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.13 - * http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#5956 - * * @param input * the stream of the class * @throws IOException * if any I/O error occurs. */ - void read( DataInputStream input ) throws IOException { + LocalVariableTable( int maxLocals, ConstantPool constantPool, DataInputStream input ) throws IOException { + this.maxLocals = maxLocals; + int count = input.readUnsignedShort(); table = new LocalVariable[count]; for( int i = 0; i < count; i++ ) { @@ -60,6 +53,18 @@ public class LocalVariableTable { } } + /** + * Create an instance without any debug details. + * + * @param maxLocals + * the count of local variables in the memory + */ + LocalVariableTable( int maxLocals ) { + this.maxLocals = maxLocals; + + table = new LocalVariable[0]; + } + /** * Get the count of variables/slots. This is not the count of declared LocalVariable in this table. There can be * unnamed helper variables for the compiler which are not in the table. There can be reused slots for different