[Soot-list] unreachable code in jimple files?

Martin Schäf martinschaef at gmail.com
Wed Aug 27 22:34:51 EDT 2014


Hi,
I'm building this tool to detect contradictions in code and I'm trying to
get rid of my false positives.
However, there seems to be some odd unreachable code in the jimple file
generated for try-catch with resources.
Here is the Java program:
    public void ex06(String name) throws Exception {
    File config = new File(name);
        try (FileOutputStream fos = new FileOutputStream(config);
                PrintWriter writer = new PrintWriter(new OutputStreamWriter(
                        fos , "rw"))) {
            bar();
        }
    }
The jimple output generated from the class file is attached. If you look at
the lines starting from 109, you have:
     label21:
        $r24 := @caughtexception;

     label22:
        r25 = $r24;
        r5 = r25;
        throw r25;

     label23:
        $r26 := @caughtexception;
        r11 = $r26;

     label24:
        if r4 == null goto label29;

        if r5 == null goto label28;
Where r5 is clearly non-null and thus the "goto label28" is unreachable.

Earlier in the code there is a chance to reach label23 with r5==null
through an exception. Unfortunately, that is preceded by another trap, so
the edge is ignored:

        catch java.lang.Throwable from label0 to label16 with label21;
        catch java.lang.Throwable from label0 to label16 with label23;

Is this something I have to live with or is there an easy way around? For
some reason the NullnessAnalysis doesn't catch that either ... probably
there is an infeasible edge in the exceptional unit graph.

Cheers,
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20140827/3f198831/attachment.html 
-------------- next part --------------
    public void ex06(java.lang.String) throws java.lang.Exception
    {
        FalsePositives05 r0;
        java.lang.String r1;
        java.io.File $r2, r3;
        java.io.FileOutputStream r4, $r13;
        java.lang.Throwable r5, r7, r8, r9, r10, r11, r12, $r17, $r18, r19, $r20, $r21, $r22, r23, $r24, r25, $r26, $r27;
        java.io.PrintWriter r6, $r14;
        java.io.OutputStreamWriter $r15;

        r0 := @this: FalsePositives05;
        r1 := @parameter0: java.lang.String;
        $r2 = new java.io.File;
        specialinvoke $r2.<java.io.File: void <init>(java.lang.String)>(r1);
        r3 = $r2;
        $r13 = new java.io.FileOutputStream;
        specialinvoke $r13.<java.io.FileOutputStream: void <init>(java.io.File)>(r3);
        r4 = $r13;
        r5 = null;

     label0:
        $r14 = new java.io.PrintWriter;
        $r15 = new java.io.OutputStreamWriter;
        specialinvoke $r15.<java.io.OutputStreamWriter: void <init>(java.io.OutputStream,java.lang.String)>(r4, "rw");
        specialinvoke $r14.<java.io.PrintWriter: void <init>(java.io.Writer)>($r15);
        r6 = $r14;
        r7 = null;

     label1:
        virtualinvoke r0.<FalsePositives05: java.io.InputStream bar()>();

     label2:
        if r6 == null goto label16;

        if r7 == null goto label6;

     label3:
        virtualinvoke r6.<java.io.PrintWriter: void close()>();

     label4:
        goto label16;

     label5:
        $r17 := @caughtexception;
        r8 = $r17;
        virtualinvoke r7.<java.lang.Throwable: void addSuppressed(java.lang.Throwable)>(r8);
        goto label16;

     label6:
        virtualinvoke r6.<java.io.PrintWriter: void close()>();
        goto label16;

     label7:
        $r18 := @caughtexception;

     label8:
        r19 = $r18;
        r7 = r19;
        throw r19;

     label9:
        $r20 := @caughtexception;
        r9 = $r20;

     label10:
        if r6 == null goto label15;

        if r7 == null goto label14;

     label11:
        virtualinvoke r6.<java.io.PrintWriter: void close()>();

     label12:
        goto label15;

     label13:
        $r21 := @caughtexception;
        r10 = $r21;
        virtualinvoke r7.<java.lang.Throwable: void addSuppressed(java.lang.Throwable)>(r10);
        goto label15;

     label14:
        virtualinvoke r6.<java.io.PrintWriter: void close()>();

     label15:
        throw r9;

     label16:
        if r4 == null goto label30;

        if r5 == null goto label20;

     label17:
        virtualinvoke r4.<java.io.FileOutputStream: void close()>();

     label18:
        goto label30;

     label19:
        $r22 := @caughtexception;
        r23 = $r22;
        virtualinvoke r5.<java.lang.Throwable: void addSuppressed(java.lang.Throwable)>(r23);
        goto label30;

     label20:
        virtualinvoke r4.<java.io.FileOutputStream: void close()>();
        goto label30;

     label21:
        $r24 := @caughtexception;

     label22:
        r25 = $r24;
        r5 = r25;
        throw r25;

     label23:
        $r26 := @caughtexception;
        r11 = $r26;

     label24:
        if r4 == null goto label29;

        if r5 == null goto label28;

     label25:
        virtualinvoke r4.<java.io.FileOutputStream: void close()>();

     label26:
        goto label29;

     label27:
        $r27 := @caughtexception;
        r12 = $r27;
        virtualinvoke r5.<java.lang.Throwable: void addSuppressed(java.lang.Throwable)>(r12);
        goto label29;

     label28:
        virtualinvoke r4.<java.io.FileOutputStream: void close()>();

     label29:
        throw r11;

     label30:
        return;

        catch java.lang.Throwable from label3 to label4 with label5;
        catch java.lang.Throwable from label1 to label2 with label7;
        catch java.lang.Throwable from label1 to label2 with label9;
        catch java.lang.Throwable from label11 to label12 with label13;
        catch java.lang.Throwable from label8 to label10 with label9;
        catch java.lang.Throwable from label17 to label18 with label19;
        catch java.lang.Throwable from label0 to label16 with label21;
        catch java.lang.Throwable from label0 to label16 with label23;
        catch java.lang.Throwable from label25 to label26 with label27;
        catch java.lang.Throwable from label22 to label24 with label23;
    }


More information about the Soot-list mailing list