User development,
A new message was posted in the thread "cannot access added Field in some cases.
Please help.":
http://community.jboss.org/message/524192#524192
Author : jaikiran pai
Profile :
http://community.jboss.org/people/jaikiran
Message:
--------------------------------------------------------------
You haven't posted your complete code nor the complete exception stacktrace (i reason
i keep insisting on these is because they can contain vital information). Anyway, i just
gave a quick try against 3.11.0.GA version javassist:
public class NewFieldTestCase extends TestCase
{
public void testSharedInterfaceAndSuperClass() throws Exception
{
CtClass dummyClass =
ClassPool.getDefault().get("org.myapp.test.javassist.Dummy");
CtField newIntField = new CtField(CtClass.intType,"myInt",dummyClass);
dummyClass.addField(newIntField);
CtMethod dummyMethod = dummyClass.getDeclaredMethod("dummyMethod");
dummyMethod.insertBefore("myInt = 10;");
byte[] modifiedDummyClassBytes = dummyClass.toBytecode();
assertTrue("Empty bytes", modifiedDummyClassBytes.length > 0);
}
}
Works fine. Test case passes, no exceptions thrown.
--------------------------------------------------------------
To reply to this message visit the message page:
http://community.jboss.org/message/524192#524192