Community
Participate
Working Groups
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
Created attachment 17204 [details] The class
Created attachment 17205 [details] the aspect
Created attachment 17206 [details] the exception
for investigation in aj5m3
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.
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.
fix checked in - waiting on build
fix available, see AJ downloads page.