You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Konstantin Scheglov <sc...@nlmk.ru> on 2003/06/11 17:00:14 UTC
Re[2]: Invalid constant pool reference: 28088. Constant pool size is: 1024
Hello Simon,
Wednesday, June 11, 2003, 6:52:25 PM, you wrote:
SB> I'm no BCEL guru, but I used it for a while a few weeks back, so maybe I
SB> can help you.
Would be great. :-)
SB> I think the problem must come from the few operations you says you do,
SB> but that don't show up on the listing you sent ... Maybe you could send
SB> the whole thing.
No, problem appears even when I don't modify method. I.e. when I use
code in initial mail.
SB> Maybe one thing, I think you need to call classGen.update() once you
SB> changed the method ... But I don't think this will be the cause of your
SB> problem.
Yes, just tryed - still same exception.
Here is archive with class. Name of class is broken, but I don't
think, that this is reason of exception.
section 1 of uuencode 5.25 of file clazz.zip by R.E.M.
sum -r/size 64782/3098 section (from "begin" to "end")
sum -r/size 25249/2228 entire input file
SB> Simon.
SB> Konstantin Scheglov wrote:
>> I use following code to instrument one class.
>> But when I instrument some classes and try to print debug
>>information, I receive following exception.
>>
>>org.apache.bcel.classfile.ClassFormatException: Invalid constant pool reference: 28088. Constant pool size is: 1024
>> at org.apache.bcel.classfile.ConstantPool.getConstant(ConstantPool.java:242)
>> at org.apache.bcel.classfile.Utility.codeToString(Utility.java:369)
>> at org.apache.bcel.classfile.Utility.codeToString(Utility.java:166)
>> at org.apache.bcel.classfile.Code.toString(Code.java:326)
>> at org.apache.bcel.classfile.Code.toString(Code.java:352)
>> at java.lang.String.valueOf(String.java:2131)
>> at java.io.PrintStream.print(PrintStream.java:462)
>> at java.io.PrintStream.println(PrintStream.java:599)
>> at ru.nlmk.eclipse.plugins.profiler.trace.Trace.instrumentClass(Trace.java:1190)
>> at ru.nlmk.eclipse.plugins.profiler.trace.test.TestBCEL.main(TestBCEL.java:23)
>>
>>
>> As you can see, I just copy code from one method to another (in real application
>>I change code a little). And when I try to load this class in real application
>>I receive exception like this from JVM: "VerifyError: Illegal constant pool index".
>>
>>
>> public static JavaClass instrumentClass(JavaClass clazz) throws Exception {
>> ClassGen classGen = new ClassGen(clazz);
>> ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
>> classGen.setConstantPool(cp);
>> //
>> for (int i = 0; i < clazz.getMethods().length; i++) {
>> Method method = clazz.getMethods()[i];
>> if (method.isAbstract() || method.isNative())
>> continue;
>> if (method.getName().equals("finalize"))
>> continue;
>> MethodGen mg = new MethodGen(method, clazz.getClassName(), cp);
>> mg.setConstantPool(cp);
>> Method newMethod = mg.getMethod();
>> if (m_Debug) {
>> System.out.println(method.getCode());
>> System.out.println(newMethod.getCode());
>> }
>> classGen.replaceMethod(method, newMethod);
>> }
>> //
>> JavaClass newClazz = classGen.getJavaClass();
>> newClazz.setConstantPool(cp.getFinalConstantPool());
>> return newClazz;
>> }
>>
>> What I do wrong?
>> I see such exception only on few classes (methods).
>> I have example of such class.
>>
>>
>>
>>
SB> ---------------------------------------------------------------------
SB> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
SB> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
--
Best regards,
Konstantin mailto:scheglov_ke@nlmk.ru