Bug 82989 - Compiler error due to a wrong exception check in try blocks
Summary: Compiler error due to a wrong exception check in try blocks
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2   Edit
Hardware: PC Linux
: P3 blocker (vote)
Target Milestone: 1.5.0 M3   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-17 12:07 EST by mariano CLA
Modified: 2005-08-25 03:20 EDT (History)
0 users

See Also:


Attachments
The class (75 bytes, text/x-java)
2005-01-17 12:08 EST, mariano CLA
no flags Details
the aspect (75 bytes, text/x-java)
2005-01-17 12:08 EST, mariano CLA
no flags Details
the exception (44 bytes, text/x-java)
2005-01-17 12:09 EST, mariano CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description mariano CLA 2005-01-17 12:07:27 EST
Compiler error on correct code when an aspect performs a method introdiction.
The method introduction contains an invocation to a method from the class and
such an invocation is inside an appropriate try block.
The ajc compiler performs a wrong check on the exception types.
To understand better, please see the attached example
Comment 1 mariano CLA 2005-01-17 12:08:17 EST
Created attachment 17204 [details]
The class
Comment 2 mariano CLA 2005-01-17 12:08:51 EST
Created attachment 17205 [details]
the aspect
Comment 3 mariano CLA 2005-01-17 12:09:18 EST
Created attachment 17206 [details]
the exception
Comment 4 Adrian Colyer CLA 2005-03-23 09:14:37 EST
for investigation in aj5m3
Comment 5 Andrew Clement CLA 2005-08-24 12:42:49 EDT
Here is the program that fails directly in the bug report:

class A {

  public A(){}

  private void m1() throws E {
    throw new E();
  }
}

privileged aspect B {

  void A.m2() {
    try {
      m1();
    } catch(E e) {
    }
  }
}

class E extends Exception{
  public E(){}
}

On compiling (with up to date AJ) you get:

C:\pr82989\poo\A.java:15 [error] Unreachable catch block for E. This exception 
is never thrown from the try statement body
} catch(E e) {

If you change m1() in A to be public rather than private, the program compiles
fine.  This suggests the accessor methods created for m1() in the A class don't
have the exception throws clauses correctly copied across.
Comment 6 Andrew Clement CLA 2005-08-24 12:52:17 EDT
Ok, I looked at AjcMemberMaker.privilegedAccessMethodForMethod() and found this
XXX comment: 

//XXX needs thrown exceptions to be correct

(so it appears I was right in my previous comment).

I rewrote the code to generate a correct accessor, now the program compiles
fine, and the accessor method looks like this in A:

public void ajc$privMethod$B$A$m1() throws E;


I need to test whether the fix affects any other tests - but it looks good.
Comment 7 Andrew Clement CLA 2005-08-24 13:51:59 EDT
fix checked in - waiting on build
Comment 8 Andrew Clement CLA 2005-08-25 03:20:52 EDT
fix available, see AJ downloads page.