jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rreye...@comcast.net
Subject Re: changing types
Date Wed, 07 Apr 2004 18:20:29 GMT
Hello,

You need to be very careful when changing UTF8 constants, because they are shared not only
by method/field signatures, they are also shared with the literal strings in the program.
For example,

public class Foo {
  IFoo foo;
  System.out.println( "LIFoo;" );
}

This class will only have one single UTF8Constant for "LIFoo;", for both the FieldRef constant
and the String constant.

It's usually a better plan just to add a new UTF8Constant into the pool, and redirect any
of the fielddref/methodref/whatever entries to that entirely new constant. It doesn't hurt
if you leave the old constant there in the pool, even if it is no longer used.

God bless,
-Toby Reyelts
> 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: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


Mime
View raw message