This content has been marked as final.
Show 2 replies
-
1. Re: Register 1 in a java.lang.VerifyError
mpresley Jul 13, 2005 5:38 PM (in response to mpresley)More details:
Here is the method I'm using to modify the toString() method in TestObjectSuper:private static void hackExistingMethod(CtMethod method) throws Exception { method.addLocalVariable("var", CtClass.booleanType); String methodStart = "{var = true;}"; method.insertBefore(methodStart); String methodEnd = "{if (var) hashCode();}"; method.insertAfter(methodEnd, true); // true --> do as finally }
It compiles fine. I get the verify error shown above. Note that if I add the assignment var = true; at the beginning of the insertAfter block, then this compiles fine.
Any idea what's going on here? Shouldn't I be able to access the add local variable "var" in the insertAfter block without problems since I initialize it in the insertBefore block? -
2. Re: Register 1 in a java.lang.VerifyError
chiba Aug 17, 2005 1:43 PM (in response to mpresley)Sorry, it's spec.
method.insertAfter(methodEnd, true); // true --> do as finally
If the second parameter to insertAfter() is true, then the local
variable declared by addLocalVariable() is not vivible in the
code inserted by insertAfter(). If the second parameter is false,
your code should work well.