VerifyError Exception :((
Abdullah Odeh Al-Zaghameem <[email protected]> Thu, 30 Apr 2009 05:18:24 -0700 (PDT)
| Newsgroups | gmane.comp.jakarta.bcel.user |
|---|---|
| Message-ID | <[email protected]> |
--0-251611671-1241093904=:25281
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hi all,,
This is my first question in bcel-mailing list. I have the following proble=
m:
I write a simple code to transform a method code such that it should invoke=
another method providing its parameters as an argument to this new method.=
for example:
// original method=20
public void orgMethod(String A, int B, Object C) {...}
//should be transformed to:
public void orgMethod(String A, int B, Object C)=20
{
=A0=A0 Object[] args =3D new Object[]{A, B, C};
=A0=A0 anotherMethod("origMethod", args);
}
The funny thing at this point is that I use the BCEL library to weave the n=
ew method's code as follow:
///////////////////////////////////////////////////////////////////////////=
/////////////////
LocalVariableGen selfArgs =3D mg2.addLocalVariable("args", new ArrayType(Ty=
pe.OBJECT, 1), null, null);
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // mg2 is an MethodGen =
instance that is initiated from origMethod .. :)
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=20
=A0LocalVariableGen for_q =3D mg2.addLocalVariable("indx", Type.INT, null, =
null);
=A0int methodNameIndex =3D cpg.addString(mg2.getName());
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new =
ICONST(mg2.getArgumentNames().length));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new =
ANEWARRAY(objectType_Index));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new =
ASTORE(selfArgs.getIndex()));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new =
ICONST(-1));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new =
ISTORE(for_q.getIndex()));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 for(int i =3D 1=
; i<=3D mg2.getArgumentNames().length; i++)
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 {=A0=A0=A0=20
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.a=
ppend(new IINC(for_q.getIndex(), 1));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.a=
ppend(new ALOAD(selfArgs.getIndex()));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.a=
ppend(new ILOAD(for_q.getIndex()));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.a=
ppend(InstructionFactory.createLoad(mg2.getArgumentTypes()[i-1], i));=20
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0 il2.app=
end(InstructionFactory.createArrayStore(Type.OBJECT));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=20
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new ALOAD(0));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new LDC(method=
NameIndex));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new ALOAD(self=
Args.getIndex()));
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(ifact.createIn=
voke(fullQualifiedClassName, "anotherMethod", Type.OBJECT, new Type[]{Type.=
STRING, new ArrayType(Type.OBJECT,1)}, Constants.INVOKEVIRTUAL));
///////////////////////////////////////////////////////////////////////////=
/////////////////
which produces a nice code!!.
public void orgMethod(String A, int B, Object C)=20
{
=A0=A0 Object[] args =3D new Object[3];
=A0=A0 int indx =3D -1;
=A0=A0 indx ++;
=A0=A0 args[indx] =3D A;
=A0=A0 indx ++;
=A0=A0 args[indx] =3D B;
=A0=A0 indx ++;
=A0=A0 args[indx] =3D C;
=A0=A0 anotherMethod("origMethod", args);
}
=A0But an exception is thrown after the new origMethod.
Exception in thread "main" java.lang.VerifyError: (class: pkg/C, method: or=
igMethod signature: (Ljava.lang.String;ILjava.lang.Object;)V) Expecting to =
find object/array on stack
any help will be so much appreciated.
Abdullah
=0A=0A=0A
--0-251611671-1241093904=:25281--