Re: VerifyError Exception :((

Abdullah Odeh Al-Zaghameem <[email protected]> Thu, 30 Apr 2009 07:13:25 -0700 (PDT)
Newsgroups gmane.comp.jakarta.bcel.user
Message-ID <[email protected]>
--0-1713719965-1241100805=:62989
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

=A0
Hi Frederic,,
=A0
Thank you so much for yr immediate response, and yes you are right, if we d=
on't want the produced value we should pop it a way. But this solves anothe=
r problem=A0i.e. when the method is of type VOID.
=A0
But, Oppps!!, the solution of my problem is to invoke "valueOf" static meth=
od for the corresponding parameter type class=A0(if the parameter=A0has a b=
asic type!!), e.g:
=A0
=A0if the parameter X is of type int then we should invoke the method=A0 In=
teger.valueOf(int) before we store the parameter in the object array :))
=A0
I am so happy now !! LOL, see you in another problem.

Cheers (only water),
Abdullah

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D
A b d u l l a h=A0=A0 O.=A0 A l - Z a g h a m e e m
Technical University of=A0 Berlin

--- On Thu, 4/30/09, Fred Gidouin <[email protected]> wrote:

From: Fred Gidouin <[email protected]>
Subject: Re: VerifyError Exception :((
To: "BCEL Users List" <[email protected]>, [email protected]
Date: Thursday, April 30, 2009, 3:42 PM

Hi Abdullah,

Your anotherMethod probably returns something. This is inconsistent
with the state of the stack after a call.

You can make it void or just add a POP instruction after the
INVOKEVIRTUAL to discard the returned value.

Hope that helps.

Frederic.

On Thu, Apr 30, 2009 at 2:18 PM, Abdullah Odeh Al-Zaghameem
<[email protected]> wrote:
>
> Hi all,,
> This is my first question in bcel-mailing list. I have the following
problem:
>
> 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
> public void orgMethod(String A, int B, Object C) {...}
>
> //should be transformed to:
>
> public void orgMethod(String A, int B, Object C)
> {
> =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
new method's code as follow:
>
>
///////////////////////////////////////////////////////////////////////////=
/////////////////
> LocalVariableGen selfArgs =3D mg2.addLocalVariable("args", new
ArrayType(Type.OBJECT, 1), null, null);
> =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 // mg2 is an MethodGe=
n instance that is
initiated from origMethod .. :)
>
> =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(ne=
w
ICONST(mg2.getArgumentNames().length));
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(ne=
w
ANEWARRAY(objectType_Index));
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(ne=
w
ASTORE(selfArgs.getIndex()));
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(ne=
w ICONST(-1));
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(ne=
w
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 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2=
..append(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=
..append(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=
..append(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.append(InstructionFactory.createLoad(mg2.getArgumentTypes()[i-1], i));
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 =A0
il2.append(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=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(meth=
odNameIndex));
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 il2.append(new
ALOAD(selfArgs.getIndex()));
> =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0
il2.append(ifact.createInvoke(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)
>
> {
>
> =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: origMethod 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-1713719965-1241100805=:62989--