[abc-users] Finally block is not executed

From: <hsadat_at_gmail.com>
Date: Wed, 11 Mar 2009 16:12:31 -0600

Hi,

I have an issue with exceptions again but not directly related (I
think) to my previous email.

I noticed that, when using abc.ja 1.3.0 to compile the following code,
the finally block is not executed when an exception is raised. I
checked the generated Jimple code (below), and it looks like the code
inside the finally has simply been copied right after the code of
try. Therefore, when an exception is raised, the finally code gets no
chance to run. Here is the code:

public class Example{
        
        public void a(String str) throws IOException
        {
                PrintWriter pr = null;
                
                pr = new PrintWriter("out.txt");
                int i = 1;
                if(i > 0)
                        i = i / (1-i);
                
                pr.println(str);
                pr.close();
                
        }

        public static void main(String[] args)
        {
                 new Example().a("test");
        }
}

aspect TestAspect{
                        
        declare soft: IOException: call(* Example.*(..));
        
        pointcut newprint(): execution(* Example.a(..));
        
        void around(): newprint()
        {
                System.out.println("Before advice ...");
                try{
                        
                        proceed();
                }
                finally
                {
                        System.out.println("Inside finally ...");

                }
                
        }
}

and here's the generated advice code (please note that it's un-
optimized code:)

    public void around$0(Abc$proceed$TestAspect$around$0, int, int,
int, java.lang.Object)
     {
         TestAspect this;
         java.io.PrintStream temp$0, temp$1;
         java.lang.String uniqueArgLocal2, uniqueArgLocal3;
         Abc$proceed$TestAspect$around$0 closureInterface1;
         int shadowID2, staticClassID3, bindMask4;
         java.lang.Object contextArgFormal$11;

         this := @this: TestAspect;
         closureInterface1 := @parameter0: Abc$proceed$TestAspect
$around$0;
         shadowID2 := @parameter1: int;
         staticClassID3 := @parameter2: int;
         bindMask4 := @parameter3: int;
         contextArgFormal$11 := @parameter4: java.lang.Object;
         temp$0 = <java.lang.System: java.io.PrintStream out>;
         uniqueArgLocal2 = "Before advice ...";
         virtualinvoke temp$0.<java.io.PrintStream: void
println(java.lang.String)>(uniqueArgLocal2);
         staticinvoke <Example: void abc$static$proceed$TestAspect
$around$0(int,int,java.lang.Object)>(shadowID2, bindMask4,
contextArgFormal$11);
         temp$1 = <java.lang.System: java.io.PrintStream out>;
         uniqueArgLocal3 = "Inside finally ...";
         virtualinvoke temp$1.<java.io.PrintStream: void
println(java.lang.String)>(uniqueArgLocal3);
         goto label0;

      label0:
         return;
     }

Thanks in advance.

--Hossein
Received on Wed Mar 11 2009 - 22:12:39 GMT

This archive was generated by hypermail 2.2.0 : Sat Mar 14 2009 - 18:00:12 GMT