[jboss-jira] [JBoss JIRA] (JASSIST-230) Javassist throws java.lang.VerifyError with dead code
Kelvin Law (JIRA)
issues at jboss.org
Mon Jul 28 07:51:29 EDT 2014
[ https://issues.jboss.org/browse/JASSIST-230?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12988251#comment-12988251 ]
Kelvin Law commented on JASSIST-230:
------------------------------------
package com.abc.test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.CtNewMethod;
public class Test {
/**
* @param args
* @throws CannotCompileException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public static void main(final String[] args) throws CannotCompileException, IllegalAccessException, InstantiationException,
NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
// TODO Auto-generated method stub
// Javassist throws VerifyError on JRE7
String method = "public void evaluate(){if (false) {int i = 0;}}";
// Javassist works on JRE 7
// String method =
// "public void evaluate(){if (false == true) {int i = 0;}}";
ClassPool pool = ClassPool.getDefault();
CtClass newClass = pool.makeClass("MyExpression");
CtMethod newmethod;
newmethod = CtNewMethod.make(method, newClass);
newClass.addMethod(newmethod);
Class<?> cClass = newClass.toClass();
Object o = cClass.newInstance();
Method m = cClass.getMethod("evaluate");
m.invoke(o);
}
}
> Javassist throws java.lang.VerifyError with dead code
> -----------------------------------------------------
>
> Key: JASSIST-230
> URL: https://issues.jboss.org/browse/JASSIST-230
> Project: Javassist
> Issue Type: Feature Request
> Security Level: Public(Everyone can see)
> Affects Versions: 3.18.2-GA
> Reporter: Kelvin Law
> Assignee: Shigeru Chiba
>
> I found the root cause of the Javassist throws java.lang.VerifyError with JRE 7, but the exact same binary works on JRE6
> It is because of dead code like the following:
> if (false) {
> do something;
> }
> These code is generated by the template:
> if (${transitory}) {
> do something;
> }
> The reason why we have such dead code in our generated java classes is, it is far more easier to code and maintain condition checking in runtime logic(in Java) instead of template logic (template expression). And we think that the if (false) statement does not make significant performance degradation in runtime.
> Although these code could be avoided, this is comply with Java 1.4/5/6/7 syntax standard thus it works with Javassist on JRE 6. Obviously It is a bug in Javassist.
> I have the following: tentative solution:
> Rewrite the if (${transitory}) with if (${transitory == true})
> I tested the above solution and found that Javassist works with that. No more java.lang.VerifyError. And I believe it does not make significant performance degradation in runtime.
--
This message was sent by Atlassian JIRA
(v6.2.6#6264)
More information about the jboss-jira
mailing list