Bug 118698 - Not Allowing Access to Private ITD inside Nested Type
Summary: Not Allowing Access to Private ITD inside Nested Type
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-30 15:18 EST by Ron Bodkin CLA
Modified: 2012-04-03 15:53 EDT (History)
0 users

See Also:


Attachments
Patch to tests module that integrates this test case into the ajc150 test suite. (2.62 KB, patch)
2005-11-30 15:24 EST, Ron Bodkin CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ron Bodkin CLA 2005-11-30 15:18:31 EST
AspectJ is failing to allow access to a private ITD field from a type nested inside the aspect, which is inconsistent with Java's access rules.

Here is the source. See also the follow up patch to tests that integrates it into the ajc150 test suite.

public aspect prUnknown {
    private static interface Marker {}   

    private class Foo implements Marker {
		public Foo() {
            bar = null; // allowed
            listener = null; // should also be allowed
            this.listener = null; // so should this
            Marker.this.listener = null; // and this
            ((Marker)this).listener = null; // and this
        }
    }

    private Object Marker.listener;
    private Object bar;
}
Comment 1 Ron Bodkin CLA 2005-11-30 15:24:56 EST
Created attachment 30893 [details]
Patch to tests module that integrates this test case into the ajc150 test suite.
Comment 2 Andrew Clement CLA 2005-12-01 10:21:53 EST
I have a fix for most of the cases.  All except 1 and I'm not sure if its a bug or not:

public aspect pr118698 {
    private static interface Marker {}   

    private class Foo implements Marker {
		public Foo() {
            bar = null; // works
            listener = null; // works
            this.listener = null; // works
            Marker.this.listener = null; // FAILS
            ((Marker)this).listener = null; // works
        }
    }

    private Object Marker.listener;
    private Object bar;
}

you can see above which case fails - with a message:

No enclosing instance of the type pr118698.Marker is accessible in scope

So I mocked up a Java equivalent (kind of...):

public class A {
    private static class Marker { private Object listener; }

    private class Foo extends Marker {
      public Foo() {
        Marker.this.listener = null; // FAILS
        ((Marker)this).listener = null; // works
      }
    }
}

The failure message in this case is the same (javac flavour message):

A.java:7: not an enclosing class: A.Marker
        Marker.this.listener = null;
              ^
1 error

So ... I'm not currently sure if the failing case with my fix in is supposed to be possible.
Comment 3 Ron Bodkin CLA 2005-12-01 12:17:38 EST
That sounds great: thanks for fixing the bug so quickly. You are right, I was trying different forms but the one that's failing should be failing:

Marker.this.listener = null;

is an error, since Marker.this is only valid in a nested type
Comment 4 Andrew Clement CLA 2005-12-02 06:06:31 EST
just checked in the test program and fix for this.
Comment 5 Andrew Clement CLA 2005-12-02 08:19:59 EST
fix available