Bug 284301 - checked exceptions and annotation style
Summary: checked exceptions and annotation style
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-22 13:06 EDT by Andrew Clement CLA
Modified: 2009-07-22 13:12 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 Andrew Clement CLA 2009-07-22 13:06:40 EDT
Was originally attached to bug 37898:

I found out that it is possible to throw checked exception that is missing in
signature of a method.
It is possible only via annotation style aspect declaration. If you try to do
same via .aj files you'll get compiler error.

Here is test case.

/** A class that doesn't declare that it throws any checked exception */
public class Foo {
    public void foo() {
    }
}
/**An aspect that throws Exception each time method Foo is  called */
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class FooAspect {
    @Around("execution(void Foo.foo())")
    public Object throwException(ProceedingJoinPoint pjp) throws Throwable {
        throw new Exception();
    }
}

/**Tests that undeclared check exception was thrown*/
import org.junit.Assert;
import org.junit.Test;

public class TextExceptionHandling {

    @Test
    public void undeclaredCheckedExceotionIsThrown() {
        try {
            new Foo().foo();
            Assert.fail();
        } catch (Exception e) {        
Assert.assertTrue(e.getClass().equals(UndeclaredThrowableException.class));
        }
    }
}
JVM supposed to throw UndeclaredThrowableException in such cases but instead
Exception is thrown. Tested on aspectj version 1.6.2 jdk 1.6.14.
Comment 1 Andrew Clement CLA 2009-07-22 13:12:51 EDT
Here is an old thread from the user list talking about throwing checked exceptions:

http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01412.html

I would say that if code style does not allow it then it is not allowed and a bug that annotation style lets it through.  This goes for all constructs really - code style is the more mature mechanism.