Re: Re: Re: Re: ClassReader exception due to bad bytecode
Buu Vinh <[email protected]>
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
Per Eugene's suggestion, I put CheckClassAdapter in the visitors chain before ClassWriter as following: ...... cr = new ClassReader(originalClassBytes); cw = new ClassWriter(cr,ClassWriter.COMPUTE_MAXS); BciClassAdapter bca = new BciClassAdapter(new CheckClassAdapter(cw), iClass); cr.accept(bca, 0); byte[] newBytes = cw.toByteArray(); ..... I used MethodVisitor.visitMaxs(0,0) in conjunction with ClassWriter(cr,ClassWriter.COMPUTE_MAXS) so that the max locals and max stacks can be automatically computed. However, CheckClassAdapter complained with the following error message: java.lang.RuntimeException: Data flow checking option requires valid, non zero maxLocals and maxStack values I then used visitMaxs(maxStacks,maxLocals) hoping that they will be override by ClassWriter(cr,ClassWriter.COMPUTE_MAXS), but CheckClassAdapter complained with the following message: java.lang.RuntimeException: Error at instruction 2: Insufficient maximum stack size.... How do I get around the above problem without having to manually compute maxStacks and maxLocals? Please advice. Thanks --- On Wed, 1/26/11, Eugene Kuleshov <[email protected]> wrote: From: Eugene Kuleshov <[email protected]> Subject: [asm] Re: Re: Re: ClassReader exception due to bad bytecode To: [email protected] Date: Wednesday, January 26, 2011, 7:57 AM A lot of issues can be caught if you put CheckClassAdapter in the visitors chain before ClassWriter. regards, Eugene On 2011-01-26 8:53 AM, "Rémi Forax" <[email protected]> wrote: > javap and ASM tell you the same thing, the way you encode your class name > (when you call ClassVisitor.visit(...)) is wrong. > > Usually it's because you use null as argument of visit(). > > Rémi > > On 01/26/2011 05:57 AM, Buu Vinh wrote: >> Thanks for the suggestion. The result of javap - v -p as following: >> >> Exception in thread "main" java.lang.NullPointerException >> at >> sun.tools.javap.JavapPrinter.javaclassname(JavapPrinter.java:856) >> at >> sun.tools.javap.JavapPrinter.printclassHeader(JavapPrinter.java:62) >> at sun.tools.javap.JavapPrinter.print(JavapPrinter.java:38) >> at sun.tools.javap.Main.displayResults(Main.java:202) >> at sun.tools.javap.Main.perform(Main.java:61) >> at sun.tools.javap.Main.entry(Main.java:49) >> at sun.tools.javap.Main.main(Main.java:34) >> >> I can't tell what is wrong with my bytecode based on the above >> messages. I would guess the problem is in the header, is it a wild >> guess? Are there tools that help to identify problems in the bytecode? >> Please advice. >> >> --- On *Tue, 1/25/11, Dave Brosius /<[email protected]>/* wrote: >> >> >> From: Dave Brosius <[email protected]> >> Subject: Re: [asm] ClassReader exception due to bad bytecode >> To: [email protected], [email protected] >> Date: Tuesday, January 25, 2011, 7:20 PM >> >> Does javap -v -private YourClass >> >> produce anything different? >> >> On 01/25/2011 04:54 PM, Buu Vinh wrote: >>> After using ASM 3.2 for the bytecode instrumentation, I tried to >>> verify the result by feeding the transformed bytecode to >>> ClassReader and invoking ASMifierClassVisitor: >>> ......... >>> cr = new ClassReader(originalBytes); >>> cw = new ClassWriter(cr,ClassWriter.COMPUTE_MAXS); >>> BciClassAdapter bca = new BciClassAdapter(cw, iClass); >>> cr.accept(bca, 0); >>> byte[] newBytes = cw.toByteArray(); >>> >>> ClassReader cr = new ClassReader(newBytes); >>> File tmpFile = new File(fileName); >>> File tmpDir = tmpFile.getParentFile(); >>> tmpDir.mkdirs(); >>> ClassVisitor cv = new ASMifierClassVisitor(new PrintWriter(tmpFile)); >>> cr.accept(cv, 0); >>> ........ >>> >>> I got ClassReader Exception when processing "newBytes": >>> >>> java.lang.ArrayIndexOutOfBoundsException: Array index out of >>> range: 51966 >>> at com.bv.asm.ClassReader.readUTF8(ClassReader.java:1946) >>> at com.bv.asm.ClassReader.readClass(ClassReader.java:2015) >>> at com.bv.asm.ClassReader.getClassName(ClassReader.java:229) >>> at >>> com.bv.bci.instrument.InstrumentClass.verify(InstrumentClass.java:287) >>> >>> >>> Apparently ClassReader was not able to parse "newBytes", I >>> assumed that "newBytes" was ill-formated due to some kind of >>> problem in my bytecode instrumenation, but I could not locate the >>> error. I used ClassWriter.COMPUTE_MAXS, but it did not help. >>> Please advice. Thanks >>> >> > -----Inline Attachment Follows----- -- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws
message-footer.txt
(text/plain, 238 B)
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws