Community
Participate
Working Groups
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; }
Created attachment 30893 [details] Patch to tests module that integrates this test case into the ajc150 test suite.
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.
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
just checked in the test program and fix for this.
fix available