It seems that InstructionTargeters are not being properly cleaned up when they are not used anymore. That is, when a targeter is replaced or removed (e.g., a LocalVariableGen is removed from a method), the targeter remains in the targeters list of its targets.
For example, MethodGen's constructor which receives a Method uses its other constructor to initialize the object:
Because this call passes null as its 4th argument, the constructor will create placeholder LocalVariableGen for the arguments (like arg0, arg1, etc). Later in this constructor the arguments will be overridden (as indicated by the comment). However, the LocalVariableGens of the placeholder arguments (as well as the LocalVariableGen for the "this" variable) will remain in the targeter lists of the first and last instructions of the instruction list.
To avoid this problem I am submitting a patch in attachment. It adds a new method to InstructionTargeter:
and implements it to remove the targeter from the target's lists. The patch also calls removeTargets() when discarding targeters in MethodGen.