Scenario: I insert into a method which has a parameterized argument some instructions and two local variables. The methods signature looks like this: public void doSomething( double d, ArrayList<Integer> list ) The method is situated in the class MyClassFile. Result: Loading the class MyClassFile which contains the new method 'doSomething' results in a ClassFormatError: LVTT entry for 'list' in class file MyClassFile does not match any LVT entry This error is not produced if the method declaration is done without generics: public void doSomething( double d, ArrayList list ) The difference is the LocalVariableTypeTable. It is not present if I do not use generics. Due to the insertion of the new instructions the start_pc and the length of the local variable have to be updated in the LocalVariableTable, which is done. But the corresponding entry in the LocalVariableTypeTable gets not updated its start_pc and length entries. LocalVariableTable ( BEFORE INSERTION ): start_pc, length, index, name 0, 26, 0, this 0, 26, 1, d 0, 26, 3, list LocalVariableTypeTable( BEFORE INSERTION ): 0, 26, 3, list LocalVariableTable ( AFTER INSERTION ): start_pc, length, index, name 44, 33, 0, this 44, 33, 1, d 44, 33, 3, list 1, 85, 4, wrapper_argumentlist 26, 60, 5, wrapper LocalVariableTypeTable( AFTER INSERTION ): 0, 26, 3, list The class works fine before the insertion. I've done bcel CVS checkout, but it did not help. The original instructions of the methods are not modified. I simply install a wrapper around the original body. I add an exception handler, therefore there is also an additional entry in the exceptiontable. I can toggle the error behaviour by using or not using the generic argument. generic -> error no generic -> no error I tried JDK 5.0 build 1.5.0-b64 and eclipse 3.1.0 build 200412162000 as a compiler. I use the JVR of the above mentioned JDK.
One possible workaround before BCEL supports Local Variable type Tables is to simply remove the table. It is optional and everything seems to work fine if you remove it. Simply loop through the attributes and remove the one named "LocalVariableTypeTable". I think the only downside is that the information won't be available to a debugger.
The proposed workaround works even with the Instrumentation.redefineClasses( ClassDefinition[] definitions ) of JDK1.5
So we this should be fixed for proper jdk 1.5 support
It looks like a dup of http://issues.apache.org/bugzilla/show_bug.cgi?id=39695
i have loop through the attributes and remove the one named "LocalVariableTypeTabe". The problem still occurs