Hi,

I am trying to change a class on-the-fly with this small program:


  |         Hello h = new Hello();
  |         h.say();
  |         ClassPool cp = new ClassPool(true);
  |         CtClass cc = cp.get("com.blabla.test.Hello");
  |         CtMethod m = cc.getDeclaredMethod("say");
  |         m.insertBefore("{ System.out.println(\"Hello.say():\"); }");
  |         Class c = cc.toClass();
  |         h = (Hello)c.newInstance();
  |         h.say();

and I get the following exception:


  | javassist.CannotCompileException: by java.lang.LinkageError: duplicate 
class definition:
  |     at javassist.ClassPool.toClass(ClassPool.java:953)
  |     at javassist.ClassPool.toClass(ClassPool.java:896)
  |     at javassist.ClassPool.toClass(ClassPool.java:854)
  |     at javassist.CtClass.toClass(CtClass.java:1053)
  |     at com.blabla.test.PlainTester.testMethodInjection(PlainTester.java:32)
  | 
  | Caused by: java.lang.LinkageError: duplicate class definition: 
com/blabla/test/Hello
  |     at java.lang.ClassLoader.defineClass1(Native Method)
  |     at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
  |     at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
  |     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  |     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  |     at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  |     at java.lang.reflect.Method.invoke(Method.java:585)
  |     at javassist.ClassPool.toClass2(ClassPool.java:965)
  |     at javassist.ClassPool.toClass(ClassPool.java:947)
  |     ... 6 more

Of course, if I don't use the Hello class before injecting that method, it 
works fine. All the sample programs that I found on the net are showing a 
method injection without any prior use. However, my requirement is that, I have 
to be able to change a class while the system is running.

Is there any way that we can do that?

Your help is greatly appreciated...


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

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

Reply via email to