Bug 42711 - tests/bugs/privilege
Summary: tests/bugs/privilege
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.1.0   Edit
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: 1.2   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-08 12:16 EDT by Miguel Pessoa Monteiro CLA
Modified: 2004-03-19 09:51 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Miguel Pessoa Monteiro CLA 2003-09-08 12:16:31 EDT
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());
   }   
}
Comment 1 Matthew Webster CLA 2003-11-10 10:21:50 EST
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.
Comment 2 Adrian Colyer CLA 2003-11-11 09:10:05 EST
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.
Comment 3 Adrian Colyer CLA 2004-03-19 09:51:08 EST
updating target flag to indicate inclusion in 1.2 release.