public class Test implements Runnable{
        
        
        public Test(){
                Thread t = new Thread(this);
                t.start();
        }
        public void run(){
                System.out.println("run");
        }
        

        /**
         * @param args
         */
        public static void main(String[] args) {
                
                Test test = new Test();

        }
        

}
-----------------------------------------------------------------------------
public class EmulatorThread implements Runnable{

        public Runnable _target;


        public EmulatorThread(Runnable target) {

                _target = target;
        }
        
        
        protected void start(){
                (new Thread(this)).start();
        }
        
    public void run()
    {
        if(_target != null)
                _target.run();
    }
}

---------------------------------------
public class MethodSetEditor extends ExprEditor {

public void edit(NewExpr m) throws CannotCompileException{
                try{
                        
                        
                        if (m.getConstructor().getDeclaringClass().getName()
                                        .equals("java.lang.Thread")) {
                                if (m.getConstructor().getSignature().equals(
                                                "(Ljava/lang/Runnable;)V")) {
                                        m.replace("{$_ = new 
EmulatorThread($1);}");
                                }
                        }
                        }
                        catch(Exception e){
                                e.printStackTrace();
                        }
}

}

-----------------------------------------
when I use the folowing codes to modify the above code:
                ClassPool pool = ClassPool.getDefault();
                
                try{
                pool.appendClassPath("D:\\eclipse\\workspace\\Javassist\\");
                
                CtClass cc = pool.makeClass(new 
FileInputStream("D:\\eclipse\\workspace\\Javassist\\Test.class"));
                
            CtField [] cts = cc.getFields();
            for(int i = 0; i < cts.length; i++){
                if(cts.getSignature().equals("Ljava/lang/Thread;"))
                        cts.setType(pool.makeClass("EmulatorThread"));
            }
            
            cc.instrument(new MethodSetEditor());
            
            cc.writeFile("E:\\");
                }
                catch(Exception e){
                        e.printStackTrace();
                }

when I run the Test. the following error occured:
Exception in thread "main" java.lang.VerifyError: (class: Test, method:  s
ignature: ()V) Incompatible object argument for function call

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3966260#3966260

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3966260
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to