-
Bug
-
Resolution: Duplicate
-
P5
-
None
-
1.1
-
x86
-
windows_95
Name: mc57594 Date: 02/21/97
As I understand the rules in section 6.6.2 of the JLS, the
following access
to B.x via a qualified name should not be allowed, because B and D are in
the same package:
======================================================
package Experiments.Test;
public class B {
protected static int x;
}
======================================================
package Experiments.Test.Test;
import Experiments.Test.B;
class S extends B {
void f () {
B.x = 5; // should not be accessible?
new B().x = 5; // should not be accessible?
}
}
======================================================
6.6.2 states that:
'If access is by a qualified type name Q.Id, where Q is a TypeName, then
the access is permitted if and only if Q is S or a subclass of S.' In the
example code, B is _not_ S or a subclass of S, so x should not be
accessible unless B and S are in the same package. The second line above
violates the next rule in 6.2.2, which similarly prohibits access to a
protected member if the access is via an expression whose type is that of
the base class.
======================================================================
- duplicates
-
JDK-4028783 protected access (JLS 6.6.2) not implemented correctly for qualified names
- Closed
-
JDK-4249096 JLS 6.6.2 not fully implemented in new compiler
- Resolved
- relates to
-
JDK-4117093 bug in protected static method calls
- Closed
-
JDK-4060943 access to another package superclass protected constructor is permitted
- Closed