Of course, I have since forgotten what problems i ran into when modifying the constant pool, so feel free to take my advice with a grain of salt. especially since my code will run a lot slower than your original idea on large programs.
[EMAIL PROTECTED] wrote:
At the momemnt I am working on some rewritings that contain the modifcation of the types of a fields and methods of an existing class. The thing is I am rewriting classes in such a way that they use don't use a class directly but an interface that I extracted from them.
E.g.
class ClassX{
private Foo f; // transformation Foo -> IFoo which is the interface
public bar() { f = null; //just a use of f to make sure there is a FieldRef in the pool } }
I could do this by creating a new field that has type IFoo and use replaceField() method and creating the new field that has the new/correct type. However taking this approach BCEL does not change the FieldRef entry of f, that is used by field instructions (putfield, getfield etc.).
In my case, all uses of Foo should be changed to IFoo, so what i _could_ do, I think is change the Utf8 entry describing the signature, using something like :
cp.setConstant(field_foo.getSignatureIndex(), new ConstantUtf8("LIFoo;")); which only changes the signature and now it is not necessary to change the FieldRef entries, because they are 'pointing' to this utf8 entry and thus the change works on the FieldRef too. This to me feels like a 'safe' modification, but I haven't found docs that describe the constantpool well enough to defend this.
I hope that others have done similar things and are able to give some feedback. Are there situations where this directly changing the Utf8 entry causes troubles? If not, does the same approach apply to method signatures?
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
