Bug 61572 - ITDs on inner classes should be static contexts
Summary: ITDs on inner classes should be static contexts
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 1.2.1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-10 06:10 EDT by Oege de Moor CLA
Modified: 2004-10-21 04:33 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 Oege de Moor CLA 2004-05-10 06:10:36 EDT
/* intertype method declarations should be a static context;
   it is incorrect to refer to instance variables of the
   originating aspect. ajc fails to check this properly when
   an ITD method is applied to an inner class.

   The example below compiles fine, but then throws

   java.lang.NoSuchFieldError: zzz

   when run.

*/

aspect NewFoo { 

    int zzz = 3;

    public void Aaa.Ccc.bar() {
	System.out.println(zzz); // illegal reference to zzz
    }
}

class Aaa {

    public class Ccc {
       
    }

    public Ccc ccc;

    public Aaa() {
       ccc = new Ccc();
    }
}

public class IllegalRef { 


    public static void main(String[] args) { 
	Aaa aaa = new Aaa();
	aaa.ccc.bar();
    } 
 
}
Comment 1 Jim Hugunin CLA 2004-05-10 14:45:19 EDT
Thanks for the clear report.  This is a valid bug.

While all bugs that turn what should be compile-time errors into runtime 
errors are bad, I think this bug should be fixed after the 1.2 release.  We're 
now in the final runup to that release (1.2rc2 has just been built) and I 
don't think this is serious enough to try to squeeze in a fix.
Comment 2 Oege de Moor CLA 2004-05-10 16:56:30 EDT
This is not merely an issue of runtime errors versus compiletime errors. It can 
introduce subtle little bugs, compiling fine and not raising an error at 
runtime. For instance, insert "int zzz = 0" into the Ccc class of the earlier 
example. This compiles and prints "0".
Comment 3 Adrian Colyer CLA 2004-08-09 15:24:36 EDT
marked as target 1.2.1
Comment 4 Adrian Colyer CLA 2004-08-10 12:02:42 EDT
Have a fix in org.eclipse.jdt.core - when testing to see if we are in a static 
scope, we were using the enclosingType rather than the invocationType (which 
differs in the case of ITDs). Need to rebuild the shadows jar, integrate and 
test yet before the fix can be committed.
Comment 5 Adrian Colyer CLA 2004-08-10 14:57:57 EDT
Fix now available in latest development jar from AspectJ download page.
Comment 6 Adrian Colyer CLA 2004-10-21 04:33:02 EDT
Fix released as part of AspectJ 1.2.1