Re: ArrayIndexOutOfBoundsException in generic.PUTFIELD
Arrin Daley <[email protected]> Tue, 26 May 2009 11:48:58 +1000
| Newsgroups | gmane.comp.jakarta.bcel.user |
|---|---|
| Message-ID | <[email protected]> |
Hi My experience is that the error you are getting is it because some method code has an invalid stack, in this case you are removing too many items from the stack, the verifier is picking this up and reporting the error. I'm not sure but perhaps some code doesn't call MethodGen.setMaxStack() after transforming, although I doubt it, because if the code were otherwise correct it should have complained of a stack overflow. The problem has to be with the method it is verifying at the time so if you can print out which method the verifier is working on and it's bytecodes you could go through it and find the problem. The bytecode pre-transformation by BCEL should be correct so the problem lies with the transformations your code performs. I'm don't know why this should be a problem with 1.5 and not 1.4. Hope it helps Bye Arrin Razvanica wrote: > Hello all, > > Here's my problem. I am trying to make some network simulations using a tool > called JiST/SWANS. This simulator has been written for Java 1.4 and, for my > simulations, I would like to use some 1.5 features, like genericity. > > So what I am trying to do is to compile the original code with the "source > -1.5" tag instead of the "source -1.4" tag. The problem is that the > simulator uses bcel to rewrite the bytecode so that JVM could be used for > simulations. The bcel library in the release doesn't work with the "source > -1.5" tag so I replace it with bcel-5.2. I made 2 minor modifications to the > original code : > - I have added an implementation of getClassPath in a class that implements > org.apache.bcel.util.Repository. This class just returns null, just like in > org.apache.bcel.util.ClassLoaderRepository > - In a class using org.apache.bcel.Repository.lookupClass() I am now > throwing java.lang.ClassNotFoundException > > These 2 modifications shouldn't change anything as far as I understand the > application. And when I compile the new code with the "-source 1.4" tag, it > doesn,t change anything. Everything compiles and works just fine. However, > when I compile the new code with the "-source 1.5" tag the compilation goes > smoothly, but, at runtime, the rewriter throws an > ArrayIndexOutOfBoundsException. > > > This happens every time org.apache.bcel.generic.PUTFIELD.accept is called: > java.lang.ArrayIndexOutOfBoundsException: -1 > at java.util.ArrayList.remove(ArrayList.java:390) > at > org.apache.bcel.verifier.structurals.OperandStack.pop(OperandStack.java:135) > at > org.apache.bcel.verifier.structurals.ExecutionVisitor.visitPUTFIELD(ExecutionVisitor.java:1048) > at org.apache.bcel.generic.PUTFIELD.accept(PUTFIELD.java:78) > > Does anybody have any idea what happens and if there's something I could do > to fix this? > > Thank you. >