Bug 37898 - advice on handler join points can throw unpermitted checked exceptions
Summary: advice on handler join points can throw unpermitted checked exceptions
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows NT
: P5 normal with 11 votes (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords: info
Depends on:
Blocks:
 
Reported: 2003-05-20 20:38 EDT by Wes Isberg CLA
Modified: 2009-07-22 13:07 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wes Isberg CLA 2003-05-20 20:38:51 EDT
Advice that throws checked exceptions can be woven for handler join points that
are not permitted to throw the checked exceptions.  The compiler should signal
an error instead, as it does for other join points.

See modules/tests/bugs/handlers/ExceptionCheckCE.java
Comment 1 Wes Isberg CLA 2003-05-20 20:39:47 EDT
adding info keyword as a tracking test
Comment 2 Jim Hugunin CLA 2003-05-21 12:28:32 EDT
This is a known limitation for 1.1.  Computing the legal checked exceptions 
for a handler join point is hard, but technically feasible.

org.aspectj.weaver.Shadow has the following XXX comment for anyone who needs a 
starting point for fixing this bug:
	protected boolean checkCanThrow(ShadowMunger munger, ResolvedTypeX 
resolvedTypeX) {
		if (getKind() == ExceptionHandler) {
			//XXX much too lenient rules here, need to walk up 
exception handlers
			return true;
		}
                ...
Comment 3 Adrian Colyer CLA 2005-03-22 08:19:30 EST
marked for consideration during AJ5 M4
Comment 4 Adrian Colyer CLA 2005-10-28 05:52:16 EDT
We looked at this for 1.5.0. Since the resolution is "hard but technically feasible" (Jim's words), and it's 
been a known issue since 1.1 with no additional user reports against it, I think it's fair to say that we 
shouldn't hold 1.5.0 for it. Moving to 1.5.1...
Comment 5 Andrew Clement CLA 2006-02-15 04:36:54 EST
1.5.1 is imminent ... fix for this isnt ... moving to post 1.5.1
Comment 6 Hans Meier CLA 2009-07-22 10:40:08 EDT
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 7 Andrew Clement CLA 2009-07-22 13:07:32 EDT
moved your comment to a new bug 284301