Bug 71723 - Inconsistency in scoping of protected members in ITDs
Summary: Inconsistency in scoping of protected members in ITDs
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.2.1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-10 13:32 EDT by Pavel Avgustinov CLA
Modified: 2004-10-21 04:31 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 Pavel Avgustinov CLA 2004-08-10 13:32:45 EDT
When introducing new member functions to existing classes via inter-type
declarations, the scoping rules that apply to the ITD bodies are the same as for
the aspect - for example, private members of the target class cannot be accessed
unless the aspect is privileged.

Similarly, protected members of classes in different packages should not be
visible in ITDs unless the aspect is privileged.

This rule is only enforced for protected members declared in the target class -
protected members that are inherited are visible from ITDs in aspects in
different packages.

The following is an example of this:

----------------------
package foo;

public class Foo extends AncientFoo {
    protected int i() { return 42; }
    public static void main(String[] args) {
	new Foo().doStuff();
    }
    public void doStuff() { }
    protected int ancientI() { return 42; }
}

class AncientFoo {
    protected int ancientI() { return -42; }
    protected int ancientJ() { return 0; }
}
----------

package bar;
import foo.Foo;

aspect Bar {
    public void Foo.doing() {
	try {
	    System.out.println(i()); // fails in ajc
	    System.out.println(ancientI()); // fails in ajc
	    System.out.println(ancientJ()); // succeeds
	    System.out.println(clone()); // succeeds
	}
	catch(Throwable t) { }
    }
    before(Foo f) : call(* doStuff(..)) && target(f) {
	f.doing();
    }
}
-------------------

All four calls in Foo.doing() should fail, as they refer to protected members of
foo.Foo from package bar. However, only the first 2 - the ones directly
declared/overridden in foo.Foo - are detected as errors, and removing them makes
the rest compile and execute.

Best wishes,
Pavel
Comment 1 Adrian Colyer CLA 2004-08-10 15:00:27 EDT
adding to my list of fun raised-by-oxford-inter-type-declaration-scoping-bugs to 
be looked at for 1.2.1 :)
Comment 2 Adrian Colyer CLA 2004-08-18 08:44:37 EDT
Fix committed in tree. Will close bug once this is available in a published 
build.
Comment 3 Adrian Colyer CLA 2004-08-18 11:44:29 EDT
Fix now available for download.
Comment 4 Adrian Colyer CLA 2004-10-21 04:31:11 EDT
Fix released as part of AspectJ 1.2.1