[Soot-list] try catch transformation question
Heejong Lee
heejong at gmail.com
Tue Jun 14 03:03:55 EDT 2011
Hi, again.
Anybody explain why this happen?
original file:
1 import java.io.*;
2
3 public class T {
4 Exception returnExpt(int x) {
5 if(x > 0) return new Exception();
6 else return new IOException();
7 }
8 void test() {
9 Exception e = returnExpt(1);
10 String x = null;
11 try {
12 throw e;
13 } catch(IOException i) {
14 System.out.println("IOException");
15 x.toUpperCase(); // no error
16 } catch(Exception ex) {
17 System.out.println("Exception");
18 x.toUpperCase(); // error
19 }
20 }
21 public static void main(String[] argv) {
22 T t = new T();
23 t.test();
24 }
25 }
jimple output(with -allow-phantom-refs -f jimple):
34 void test()
35 {
36 T r0;
37 java.lang.Exception r1, $r6, r7;
38 null_type n0;
39 java.io.IOException r2, $r3;
40 java.io.PrintStream $r4, $r8;
41
42 r0 := @this: T;
43 r1 = virtualinvoke r0.<T: java.lang.Exception returnExpt(int)>(1);
44 n0 = null;
45
46 label0:
47 throw r1;
48
49 label1:
50 $r3 := @caughtexception;
51 r2 = $r3;
52 $r4 = <java.lang.System: java.io.PrintStream out>;
53 virtualinvoke $r4.<java.io.PrintStream: void
println(java.lang.String)>("IOException");
54 virtualinvoke n0.<java.lang.String: java.lang.String
toUpperCase()>();
55 goto label2;
56
57 label2:
58 return;
59
60 catch java.io.IOException from label0 to label1 with label1;
61 }
Where is a trap for java.lang.Exception after transformation?
FYI, the bytecode is normal:
void test();
Code:
0: aload_0
1: iconst_1
2: invokevirtual #6; //Method returnExpt:(I)Ljava/lang/Exception;
5: astore_1
6: aconst_null
7: astore_2
8: aload_1
9: athrow
10: astore_3
11: getstatic #7; //Field java/lang/System.out:Ljava/io/PrintStream;
14: ldc #8; //String IOException
16: invokevirtual #9; //Method
java/io/PrintStream.println:(Ljava/lang/String;)V
19: aload_2
20: invokevirtual #10; //Method
java/lang/String.toUpperCase:()Ljava/lang/String;
23: pop
24: goto 41
27: astore_3
28: getstatic #7; //Field java/lang/System.out:Ljava/io/PrintStream;
31: ldc #11; //String Exception
33: invokevirtual #9; //Method
java/io/PrintStream.println:(Ljava/lang/String;)V
36: aload_2
37: invokevirtual #10; //Method
java/lang/String.toUpperCase:()Ljava/lang/String;
40: pop
41: return
Exception table:
from to target type
8 10 10 Class java/io/IOException
8 10 27 Class java/lang/Exception
Thanks in advance!
--
Heejong Lee
Associate Research Engineer
Program Analysis Division
Fasoo.com, Inc. (www.spa-arrow.com)
More information about the Soot-list
mailing list