]
Shigeru Chiba resolved JASSIST-210.
-----------------------------------
Resolution: Unresolved
MethodCall.replace() throws inconsistent stack height in certain
scenarios
--------------------------------------------------------------------------
Key: JASSIST-210
URL:
https://issues.jboss.org/browse/JASSIST-210
Project: Javassist
Issue Type: Bug
Affects Versions: 3.16.1-GA, 3.18.1-GA
Reporter: Patson Luk
Assignee: Shigeru Chiba
Tested on 3.16.1-GA
This is similar to
https://issues.jboss.org/browse/JASSIST-52, but the try-catch block
usage is different (not wrapping the $proceed($$))
Based on the javassist tutorial, the substituted code for MethodCall.replace():
{{Note that the substituted code is not an expression but a statement or a block. It
cannot be or contain a try-catch statement.}}
However in the case that try-catch does not wrap the $_=$proceed($$);
It seems to work properly. For example:
ctClass.instrument(new ExprEditor() {
public void edit(MethodCall m) throws CannotCompileException {
if (m.getMethodName().equals("testMethod2")) {
String newBlock = "{ try { System.out.println(\"injected\"); }
catch (Exception e) { e.printStackTrace(); } $_ = $proceed($$); }";
m.replace(newBlock);
}
}
});
{{which ctClass is class TestReplace, which has code as below:}}
public class TestReplace {
public static void main(String[] args) {
RefClass ref = new RefClass();
ref.testMethod2();
}
}
class RefClass {
public void testMethod1(Object o) {}
public Object testMethod2() { return null; }
}
{{running TestReplace with the modified bytecode correctly prints "injected" to
the screen. However if I add one more line to the TestReplace's main() method}}
ref.testMethod1(ref.testMethod2());
{{It throws exception as below}}
javassist.bytecode.BadBytecode: inconsistent stack height -1
javassist.bytecode.stackmap.Tracer.doOpcode(Tracer.java:106)
*So is try-catch acceptable if it does not wrap the $_=$proceed($$)? If so, is it a bug
if it does not work properly for method invocation within another method invocation?*
Many thanks in advance!
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: