[
https://issues.jboss.org/browse/JASSIST-149?page=com.atlassian.jira.plugi...
]
Ben Romberg updated JASSIST-149:
--------------------------------
Summary: ClassFormatError when using an ExprEditor, replacing a
MethodCall after using insertBefore in a FieldAccess (was: ClassFormatError when using an
ExprEditor, replacing a MethodCall after replacing a FieldAccess with a throw-Statement)
Workaround Description: Set a boolean field in the ExprEditor after using
insertBefore, advising all following calls to edit not to replace any code. (was: Set a
boolean field in the ExprEditor after inserting the throw-Expression, advising all
following calls to edit not to replace any code.)
Description:
To reproduce, use the following ExprEditor:
new ExprEditor() {
edit(FieldAccess fieldAccess) {
behavior.insertBefore(...);
}
edit(MethodCall methodCall) {
methodCall.replace(...);
}
}
Now, use the ExprEditor on a method assigning a field first and then calling a method.
When loading the modified class, the following exception should occur:
java.lang.ClassFormatError: Invalid pc in LineNumberTable in class file
de/andrena/next/systemtest/pure/PureOnlyForOwnMethodsFieldsAndParametersSystemTest$TargetClass
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredFields(Class.java:1743)
...
Expected behavior:
* Either correctly replacing the methodCall without corrupting the line-number-table, or
* throwing a CannotCompileException when trying to insertBefore within an ExprEditor.
was:
To reproduce, use the following ExprEditor:
new ExprEditor() {
edit(FieldAccess fieldAccess) {
fieldAccess.replace("throw new ...");
}
edit(MethodCall methodCall) {
methodCall.replace(...);
}
}
Now, use the ExprEditor on a method assigning a field first and then calling a method.
When loading the modified class, the following exception should occur:
java.lang.ClassFormatError: Invalid pc in LineNumberTable in class file
de/andrena/next/systemtest/pure/PureOnlyForOwnMethodsFieldsAndParametersSystemTest$TargetClass
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredFields(Class.java:1743)
...
Expected behavior:
* Either correctly replacing the methodCall without corrupting the line-number-table, or
* throwing a CannotCompileException when trying to modify/insert code after a
throw-Expression.
ClassFormatError when using an ExprEditor, replacing a MethodCall
after using insertBefore in a FieldAccess
-----------------------------------------------------------------------------------------------------------
Key: JASSIST-149
URL:
https://issues.jboss.org/browse/JASSIST-149
Project: Javassist
Issue Type: Bug
Affects Versions: 3.15.0-GA
Environment: JRE 1.6
Reporter: Ben Romberg
Assignee: Shigeru Chiba
To reproduce, use the following ExprEditor:
new ExprEditor() {
edit(FieldAccess fieldAccess) {
behavior.insertBefore(...);
}
edit(MethodCall methodCall) {
methodCall.replace(...);
}
}
Now, use the ExprEditor on a method assigning a field first and then calling a method.
When loading the modified class, the following exception should occur:
java.lang.ClassFormatError: Invalid pc in LineNumberTable in class file
de/andrena/next/systemtest/pure/PureOnlyForOwnMethodsFieldsAndParametersSystemTest$TargetClass
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredFields(Class.java:1743)
...
Expected behavior:
* Either correctly replacing the methodCall without corrupting the line-number-table, or
* throwing a CannotCompileException when trying to insertBefore within an ExprEditor.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira