Bug 72157 - declare soft can cause programs with invalid exception behaviour to be generated
Summary: declare soft can cause programs with invalid exception behaviour to be generated
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.2.1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-18 06:39 EDT by Ganesh Sittampalam CLA
Modified: 2004-10-21 04:31 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ganesh Sittampalam CLA 2004-08-18 06:39:42 EDT
Compiling the program below results in the constructor for the class SCE2
throwing Exception, which it is not declared to throw either in the source code
or in the generated bytecode. If the 'declare soft' statement is removed, then
the super() call in the SCE2 constructor is correctly reported as throwing an
undeclared exception; it seems that the 'declare soft' statement turns off the
exception checking of the super() call despite there being no join point which
covers this call that would actually soften the exception.

I'm using 'DEVELOPMENT built on Monday Aug 16, 2004 at 13:50:47 GMT'.

public class SuperConsExc {
    public SuperConsExc() throws Exception {
	throw new Exception();
    }

    public static void main(String[] args) {
	new SCE2();
    }
}

class SCE2 extends SuperConsExc {
    public SCE2() {
	super();
    }
}

aspect SCEAspect {
    declare soft: Exception: within(SCE2);
}
Comment 1 Adrian Colyer CLA 2004-08-25 03:15:40 EDT
marked as target 1.2.1
Comment 2 Adrian Colyer CLA 2004-09-07 12:06:28 EDT
This program looks like it is behaving correctly to me?

within(SCE2) matches the execution join point for SCE2.new(), and softens 
exceptions that occur during its execution.

Consider the analogous program (which eliminates the super() call confusion):

class Foo {

  public void foo() throws Exception {
    throw new Exception();
  }

  public void goo() {
    foo();
  }

}

This will give an unhandled exception compilation error as is, but if you add
declare soft : Exception : execution(* goo(..));
it will compile happily.
Comment 3 Ganesh Sittampalam CLA 2004-09-07 12:17:31 EDT
In your example, the thrown Exception actually does get softened; but in my
example it doesn't, leading to a checked exception being thrown at runtime by a
method not declared to throw it.

The super() call is crucial to my example, because the problem is that the
execution join point for a constructor does not cover the super() call.
Comment 4 Adrian Colyer CLA 2004-09-07 12:30:17 EDT
Got it, thanks. Should have read more carefully. Have re-opened bug.

Interesting problem since:

class Foo {

  Foo() {}

}

class Boo extends Foo {

  Boo() {
   try {
     super();
   } catch(Error e) {}
  }
}

is not a valid program. Therefore the correct behaviour must be to NOT soften 
the exception, which is consistent with the definition of execution join points 
as beginning after the super call.
Comment 5 Adrian Colyer CLA 2004-09-08 08:11:20 EDT
Fix in tree. Waiting for development build before closing.
Comment 6 Adrian Colyer CLA 2004-09-08 11:56:00 EDT
Fix now available for download.
Comment 7 Adrian Colyer CLA 2004-10-21 04:31:33 EDT
Fix released as part of AspectJ 1.2.1