I've tested javassist 3 (beta), recompiling my sources with the above library, but the
behavior of the shown code has not changed. I've substituted the aPool.write() call
with a call toBytecode() over the CtClass object, but I'm still able to copy
duplicated members as detailed in previous
Well, I suppose it suffices the field_info is different, since even adding fields of
the same type works. I've tried it both with a primitice type (an int) and an object
(a string), both with the same name and the same access specifier (even if this should
not change things) and it works.
Luca
Well, src and dest are different CtClass, I mean they are produced from different
classes. When I try to define the class, in my classloader, as:
/* create the pools */
ClassPool aPool=ClassPool.getDefault();
this.addClasspathToPoll(aPool);
.
byte[]
Here is my thought.
The JVM throws an exception if a class has two
methods with the same name and signature
becuase such a class cannot pass the bytecode
verification. This is the spec.
I guess the reason that the JVM accepts a class
that has two fields with the same name is because
the JVM
Are src and dest different CtClass objects?
If yes, the problem is not adding copied
methods. I think maybe your way of using a
class loader is somewhat wrong. Can you show
me the code that throws ClassFormatError?
View the original post :
I have just released 3.0 beta!
This version rejects such a duplicated member.
In principle, you can add a duplicated member to
a class file but the JVM will reject that class file
since it does not pass bytecode verification.
View the original post :
Maybe I'm misunderstanding but I've the following code to work on my system:
CtField fields[]=src.getDeclaredFields();
CtField addingField=null;
for(int i=0;ifields.length;i++) {
addingField=new CtField(fields.getType(),fields.getName(),dest);