Hi Frederic,, Thank you so much for yr immediate response, and yes you are right, if we don't want the produced value we should pop it a way. But this solves another problem i.e. when the method is of type VOID. But, Oppps!!, the solution of my problem is to invoke "valueOf" static method for the corresponding parameter type class (if the parameter has a basic type!!), e.g: if the parameter X is of type int then we should invoke the method Integer.valueOf(int) before we store the parameter in the object array :)) I am so happy now !! LOL, see you in another problem.
Cheers (only water), Abdullah =============================== A b d u l l a h O. A l - Z a g h a m e e m Technical University of Berlin --- On Thu, 4/30/09, Fred Gidouin <gido...@gmail.com> wrote: From: Fred Gidouin <gido...@gmail.com> Subject: Re: VerifyError Exception :(( To: "BCEL Users List" <bcel-user@jakarta.apache.org>, aoz_0...@yahoo.com 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 <aoz_0...@yahoo.com> 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) > { > Object[] args = new Object[]{A, B, C}; > 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 = mg2.addLocalVariable("args", new ArrayType(Type.OBJECT, 1), null, null); > // mg2 is an MethodGen instance that is initiated from origMethod .. :) > > LocalVariableGen for_q = mg2.addLocalVariable("indx", Type.INT, null, null); > int methodNameIndex = cpg.addString(mg2.getName()); > il2.append(new ICONST(mg2.getArgumentNames().length)); > il2.append(new ANEWARRAY(objectType_Index)); > il2.append(new ASTORE(selfArgs.getIndex())); > il2.append(new ICONST(-1)); > il2.append(new ISTORE(for_q.getIndex())); > for(int i = 1; i<= mg2.getArgumentNames().length; i++) > { > il2..append(new IINC(for_q.getIndex(), 1)); > il2..append(new ALOAD(selfArgs.getIndex())); > il2..append(new ILOAD(for_q.getIndex())); > il2.append(InstructionFactory.createLoad(mg2.getArgumentTypes()[i-1], i)); > il2.append(InstructionFactory.createArrayStore(Type.OBJECT)); > > } > > il2.append(new ALOAD(0)); > il2.append(new LDC(methodNameIndex)); > il2.append(new ALOAD(selfArgs.getIndex())); > 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) > > { > > Object[] args = new Object[3]; > int indx = -1; > indx ++; > args[indx] = A; > indx ++; > > args[indx] = B; > indx ++; > > args[indx] = C; > > anotherMethod("origMethod", args); > > } > But 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 > > > > >