Hai
     I am trying to write a program using bcel api
such the before every method first statement,an object
call abc will be created and it will call a method
runCode().
     class Test
      {
            public static void main()
            {
               Instrument abc = new Instrument();
                abc.runCode();
             }
       }
I followed  the sample HelloWorldBuilder.java program
but I am getting verifier error saying Illegal
constant pool index.I have the Instrument.class which
has runCode method in the same directory as Test
class.
The code is enclosed -  the following code executes
for every method.
/////////////////////////////////////////////
InstructionFactory factory = new InstructionFacto(cg);
InstructionList il = new InstructionList();
// create instrumentor object and store it in local
variable abc
il.append(factory.createNew("Instrument"));
il.append(InstructionConstants.DUP);
//call instrumentor
il.append(factory.createInvoke("Instrument","<init>",Type.VOID,Type.NO_ARGS,Constants.INVOKESPECIAL));
                
//create a local variable
LocalVariableGen lg = mg.addLocalVariable("abc",new
ObjectType("Instrument"),null,null);
int abc = lg.getIndex();
//il.append(InstructionConstants.ACONST_NULL);
lg.setStart(il.append(new ASTORE(abc))); //abc should
be available from here
                        
 il.append(new ALOAD(abc));

il.append(factory.createInvoke("Instrument","runCode",Type.VOID,Type.NO_ARGS,Constants.INVOKEVIRTUAL));
InstructionList il1  = mg.getInstructionList();
InstructionHandle[] ihs = il1.getInstructionHandles();

/* Instrument method start */
 il1.insert(ihs[0],il);
/////////////////////////////////////////////////
What all i am trying to do is:
Instrument abc = new Instrument();
abc.runCode();
at the beginning of evry method.

The error is :
Exception in thread "main" java.lang.VerifyError:
(class: Test, method: main signature:
([Ljava/lang/String;)V) Illegal
type in constant pool

I am really stuck at this...Please help me out.Your
help is highly appreciated.

Thank you
Ram


=====
C.Kalyan Ram
2221,S St
Apt #23,Lincoln
NE-68503
Email:[EMAIL PROTECTED]
Ph:(402)742-9671
University Of Nebraska-Lincoln

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to