Community
Participate
Working Groups
I bumped into a compiler error when trying to make an privileged aspect call a method with a package-protected (default) access. I was using j2sdk1.4.0_02, AspectJ 1.1, eclipse 2.1 (with AJDT 1.1.3). I managed to isolate the problem into the following toy example, in which aspect concern.ContextUser tries to advise class core.Base. After a few experiments I got the impression that the error was triggered by the use of interfaces in the method's signature (notice the difference between the 2 package-protected methods from core.Base). If you uncomment the call to base.packageprotected_interface(List) at the end of the advice the compiler complains that the method is not visible. Is this an AspectJ bug, or am I missing something? ----------------------------------------------------------------- package core; import java.util.List; public class Base { void packageprotected() { System.out.println("package-protected access."); } void packageprotected_interface(List list) { System.out.println("pack-protected access (interface)"); } public void trigger(Base argument) { System.out.println("doing something with " + argument); } public static void main(String[] args) { Base user = new Base(); user.trigger(new Base()); } } ----------------------------------------------------------------- package concern; import java.util.ArrayList; import core.Base; public privileged aspect ContextUser { pointcut call2trigger(Base argument): execution(* core.Base.trigger(..)) && args(argument); before(Base base): call2trigger(base) { System.out.println("Before trigger (" + base + ")"); base.packageprotected(); //base.packageprotected_interface(new ArrayList()); } }
This bug is actually very subtle. AspectJ needs to generate accessor methods (similar to the mechanism inner classes use) in order to invoke non-public methods i.e. advice->accessor->method. The bug is that AspectJ is looking for an accessor that takes an ArrayList arguement rather than a list. So a workaround would be: before(Base base): call2trigger(base) { System.out.println("Before trigger (" + base + ")"); base.packageprotected(); List list = new ArrayList(); base.packageprotected_interface(list); } I suspect there is some type hierarchy search code missing.
Integrated a patch from George Harley which fixes this problem. Changes commited in org.eclipse.jdt.core under modules and also in branch aj_v_315_R21x in shadows.
updating target flag to indicate inclusion in 1.2 release.