Community
Participate
Working Groups
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); }
marked as target 1.2.1
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.
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.
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.
Fix in tree. Waiting for development build before closing.
Fix now available for download.
Fix released as part of AspectJ 1.2.1