Community
Participate
Working Groups
/* 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(); } }
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.
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".
marked as target 1.2.1
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.
Fix now available in latest development jar from AspectJ download page.
Fix released as part of AspectJ 1.2.1