diff --git a/src/de/inetsoftware/classparser/LocalVariableTable.java b/src/de/inetsoftware/classparser/LocalVariableTable.java index e211fc4..7e7c8fb 100644 --- a/src/de/inetsoftware/classparser/LocalVariableTable.java +++ b/src/de/inetsoftware/classparser/LocalVariableTable.java @@ -1,5 +1,5 @@ /* - Copyright 2011 - 2018 Volker Berlin (i-net software) + Copyright 2011 - 2019 Volker Berlin (i-net software) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -62,22 +62,24 @@ public class LocalVariableTable { */ void read( DataInputStream input, boolean withPositions ) throws IOException { count = input.readUnsignedShort(); - if( count > table.length ) { - table = new LocalVariable[count]; - tablePosition = new LocalVariable[count]; - } boolean[] wasSet = new boolean[table.length]; for( int i = 0; i < count; i++ ) { LocalVariable var = new LocalVariable( input, i, constantPool ); int idx = var.getIndex(); - if( withPositions ) { - tablePosition[i] = var; - } if( !wasSet[idx] ) { // does not use index of reused variable table[idx] = var; wasSet[idx] = true; } } + + if( withPositions ) { + for( int i = 0, t = 0; i < table.length; i++ ) { + LocalVariable var = table[i]; + if( var != null ) { + tablePosition[t++] = var; + } + } + } } /** @@ -85,7 +87,7 @@ public class LocalVariableTable { * @return the count */ public int getPositionSize() { - return count; + return tablePosition.length; } /**