[jboss-jira] [JBoss JIRA] Created: (JASSIST-51) Editing a NewExpr results in a VerifyError (inconsistent stack height)

Yanic Inghelbrecht (JIRA) jira-events at lists.jboss.org
Mon Mar 10 14:56:01 EDT 2008


Editing a NewExpr results in a VerifyError (inconsistent stack height)
----------------------------------------------------------------------

                 Key: JASSIST-51
                 URL: http://jira.jboss.com/jira/browse/JASSIST-51
             Project: Javassist
          Issue Type: Bug
         Environment: Javassist 3.7, JDK 1.6.0_03 on WinXP
            Reporter: Yanic Inghelbrecht
         Assigned To: Shigeru Chiba


The code below is the simplest case I could find that reproduces the error. The code contains two classes : Client and Main. Client is the class that gets instrumented, Main does the instrumenting. The error that result is :

Exception in thread "main" java.lang.VerifyError: (class: test_try_catch/Client, method: instrumentMe signature: ()V) Inconsistent stack height 0 != 1
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
	at java.lang.Class.getConstructor0(Unknown Source)
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at test_try_catch.Main.main(Main.java:30)

Javassist somehow messes up on instrumenting the NewExpr in method Client#instrumentMe

The weird thing about this bug is, the verifyError only occurs when the method containing the NewExpr also contains a try/catch block! 

For me this is a show stopper, not using  try/catch blocks is not really an option :o)

I hope you agree this is a high priority issue, because our project cannot be released because of this.

Best regards,
Yanic

--------- source code for Client.java below

package test_try_catch;

import java.util.ArrayList;

public class Client {
	public void instrumentMe() {
		// we need a 'new' expression to instrument, the exact type is not important
		new Object();
		
		// if the try/catch block below is removed, the error does not occur
		try {
			System.out.println();
		} catch (Throwable t) {
			//
		}
	}

}

--------- source code for Main.java below

package test_try_catch;
import java.lang.reflect.Method;

import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.Loader;
import javassist.NotFoundException;
import javassist.Translator;
import javassist.expr.ExprEditor;
import javassist.expr.NewExpr;


public class Main {
	public static void main(String[] args) throws Exception {
		ClassPool pool = new ClassPool(true);
		Loader cl = new Loader();
		try {
			cl.addTranslator(pool, new MyTranslator());
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
		
		// load the Client class
		Class clientClass=cl.loadClass("test_try_catch.Client");
		
		// create an instance
		Object client=clientClass.newInstance();
		
		// execute Client#instrumentMe
		Method callMethod=clientClass.getMethod("instrumentMe", new Class[]{});
		callMethod.invoke(client, new Object[]{});
	}
	
	static public class MyTranslator extends ExprEditor implements Translator {

		public void onLoad(ClassPool pool, String classname) throws NotFoundException, CannotCompileException {
			CtClass cc = pool.get(classname);
			modify(cc);
		}

		public void modify(CtClass c) throws CannotCompileException {
			for (CtMethod m : c.getMethods()) {
				m.instrument(this);
			}
		}

		@Override
		public void edit(NewExpr m) throws CannotCompileException {
			// no changes, for simplicity's sake
			String block = "{$_=$proceed($$);}";
			m.replace(block);
		}

		public void start(ClassPool pool) throws NotFoundException, CannotCompileException {
			// do nothing
		}
	}	
}








-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list