Community
Participate
Working Groups
Trying to access a protected field of a superclass within a subclass that resides in another package gives the error: field is not visible. This bug only happens if the subclass is in another package and has a class parameters. Accessing the field of the this object also works. Example: package test; class Foo { protected String s; } package test2; import test.Foo; class FooBar<R> extends Foo { void fail() { FooBar f = new FooBar(); f.s = "foo"; // Error: field f.s is not visible this.b = false // Works } }
Sorry, it must be: this.s = "foo"; // Works instead of this.b = false // Works
Philippe, what do you want to do with this? In the call to FieldBinding canBeSeenBy(TypeBinding receiverType, InvocationSite invocationSite, Scope scope) the receiverType is FooBar#RAW so the comparison to the declaringClass fails.
Used erasure to compare identical. Added GenericTypeTest#test467-468. Fixed
Is there a chance to get a patch against M4?
OK. The previous example works now, but the bug is still there in a slightly modified example. This time the superclass is generic, too: package test; public class Foo<R> { protected R s; } package test2; import test.Foo; public class FooBar<R> extends Foo<R> { void fail() { FooBar<String> f = new FooBar<String>(); f.s = "foo"; // Error: field f.s not visible } }
Thanks for noticing it. Added GenericTypeTest#test471-472. Fixed. You can grab the next nightly build output, copy the org.eclipse.jdt.core plugin from it and paste it into a M4 install.
Fixed
I have downloaded the HEAD from CVS and it works now! Thank you!
Verified in I20050214