Re: Re: Re: IllegalStateException: Try catch blocks must be visited before their labels

Rajaraman Santhanam <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <12dea4fcba2.-3521989097551699074.5605848841916937049@zohocorp.com>
Hi,

Can anybody comment on this? 


Thanks.

---- On Mon, 31 Jan 2011 19:43:31 +0530 Rajaraman Santhanam &lt;[email protected]&gt; wrote ---- 

Hi Tronje,

What you say makes sense. Either VM is a bit lenient or CheckClassAdaptor is strict.


I tried with a simple java file and this seems to be the behavior. I get the issue only when I keep CheckClassAdapter in front of my visitors.
MyClassAdapter adapter =  new MyClassAdapter(new CheckClassAdapter(writer), className, classBeingRedefined); 



Also I found that, if I run the CheckClassAdapter(as below) after bytecode transformation I don't see any issue at all.
StringWriter checkClassSW = new StringWriter();
PrintWriter checkClassPW = new PrintWriter(checkClassSW);
CheckClassAdapter.verify(reader, loader, dump, checkClassPW);
System.out.println(checkClassSW.toString());
try
{
            checkClassPW.close();
            checkClassSW.close();
}
catch(Exception ex)
{
            ex.printStackTrace();
} 


It looks like CheckClassAdaptor looks for some state and it finds visitLabel called before trycatchblock. However the same adaptor behaves differently :-( 

Also attaching the sources I used for testing.


Thanks,
Rajaraman




---- On Sat, 29 Jan 2011 21:15:52 +0530 Tronje Krop &lt;[email protected]&gt; wrote ---- 

Hi Rajaraman, 
 
it is as the error says. You have instrumented the byte-code in a way 
that at least one of the labels has been visited before defining the 
try-catch-block. The CheckMethodAdapter checks this requirement and 
throws the exception. 
 
If you are right with your claim, it seems that the VM-Verifier has a 
relaxed condition which allows to define the try-catch-block using labels 
have being visited before. 
 
I didn't find a rule in the VM-specification that prohibits this, but 
I have not looked very close. Therefore, I think the CheckClassAdapter 
may be to restrictive unless ASM has a problem with this relaxed 
condition. 
 
I think we must investigate this issue closer. 
 
CU Tronje 
 
 
Rajaraman Santhanam wrote: 
&gt; Hi, 
&gt; 
&gt; I get this exception if I put CheckClassAdapter in the visitors chain before ClassWriter. The code I use is below: 
&gt; ClassReader reader = new ClassReader(classfileBuffer); 
&gt; ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_MAXS); 
&gt; 
&gt; 
&gt; BasicClassAdapter adapter = new BasicClassAdapter(new CheckClassAdapter(writer), className, classBeingRedefined); 
&gt; reader.accept(adapter, ClassReader.SKIP_DEBUG); 
&gt; 
&gt; By running this I get error with details: 
&gt; java.lang.IllegalStateException: Try catch blocks must be visited before their labels 
&gt; at org.objectweb.asm.util.CheckMethodAdapter.visitTryCatchBlock(CheckMethodAdapter.java:679) 
&gt; at org.objectweb.asm.MethodAdapter.visitTryCatchBlock(MethodAdapter.java:170) 
&gt; at test.agent.instrumentation.BasicMethodAdapter.visitMaxs(BasicMethodAdapter.java:86) 
&gt; 
&gt; However my instrumentation code work perfectly well if run this without CheckClassAdapter. Not sure what I'm missing here. 
&gt; 
&gt; 
&gt; I tried this when seeing the mail from Eugene to use CheckClassAdapter to catch various issues. 
&gt; 
&gt; 
&gt; My BasicClassAdapter is the implementation of FinallyAdapter from asm-transformations.pdf 
&gt; 
&gt; 
&gt; Can somebody help me out here? 
&gt; 
&gt; 
&gt; Regards, 
&gt; Rajaraman 
&gt; 
&gt; 
&gt; 
&gt; 
 
-- 
 Tronje Krop &lt;[email protected]&gt; 
 
 Encrypted eMail welcome! GPG/PGP-Key: 0x9AD43A05 
 68E5 A3D3 75A0 B096 AC75 62D5 8EEE 3D18 9AD4 3A05 
 
 No responsibility is taken for the correctness of the 
previous information. Please delete if you receive this 
 mail unintentional.
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.