I am trying to change super class of an existing class. I have 2 classes . I want to extend one from other and write back the class file. I do it by following way.
out.println("Extension updating class file: InputFile "+inputFile+" extending from "+ExtendFile); JavaClass oldClass = Repository.lookupClass(inputFile); JavaClass newSuper = Repository.lookupClass(ExtendFile); JavaClass[] interfaces = oldClass.getAllInterfaces(); boolean alreadyExtended = false; for (int i=0; i<interfaces.length; i++) { JavaClass itf = interfaces[i]; String itfName = itf.getClassName(); if (itfName.equals(ExtendFile)) alreadyExtended = true; } if (!alreadyExtended) { ClassGen cg = new ClassGen( oldClass ); if(!oldClass.isInterface()) cg.setSuperclassName(newSuper.getClassName()); else cg.addInterface(newSuper.getClassName()); cg.update(); String className = oldClass.getClassName(); String path = Repository.lookupClassFile(className).getPath(); File f = new File(path); cg.getJavaClass().dump(f); out.println("Extension update: successful"); } else { out.println("Extension update: ignore, already extended from this class/interface"); } But i get error when i load the class. Call to wrong initialization method at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:141) Both of my class has constructor which takes one parameter and call super constructor. Looks like it changes the super class name , but the doesn't change the reference of the super. For example if B extends A and C extends A, i want to make C extends B. But after applying BCEL, C constructor which has a super call still refer to A , not B. Please help. I don't know if i miss something. Thanks. -- View this message in context: http://www.nabble.com/Change-super-class-of-a-class-tf2466469.html#a6875790 Sent from the BCEL - Dev mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]