jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dweim...@students.cs.uu.nl
Subject Re: changing types
Date Wed, 07 Apr 2004 19:00:32 GMT
Thanks for the response,

> i've done things like this a few times, and i've always run into a bunch
> of weird corner cases if i screw around with the constant pool.  the way
> i always end up doing it and getting it right is by replacing the field
> and then looking at every instruction and changing the instructions that
> reference the old field. BTW, if you use InstructionFactory, you don't
> have to screw around with the constant pool, which i always try to do
> through having been burned in the past.

What do you mean by 'changing the instructions that reference the old
field'? My approach would be to use ClassGen.replaceField(old, new); And
then change al references to this field at once:

if (cp.lookupFieldref(cg.getClassName(), fields[i].getName(),
fields[i].getSignature()) != -1)
  cp.setConstant(cp.lookupFieldref(cg.getClassName(), fields[i].getName(),
                 new ConstantFieldref(cg.getClassNameIndex(),

although this is a direct modification of the constant pool, it's not as
evil as my initial approach ;) But maybe I'm wrong and there are problems
with this too..

PS When using replaceField, BCEL knows that the other is replaced and thus
this constantpool modification could be done by BCEL..

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

View raw message