Name: el35337 Date: 01/17/97
This extends the scope of bug 4023931 and explains its cause.
Javac, as well the virtual machine, allows a subclass D of C in a package pd
to inherit the package-private attributes and methods of a public class C of
another package pc. This violates encapsulation. The bug already existed in
JDK 1.02.
Symptom. Within package pd, and especially within the class D itself,
references to those inherited attributes or methods are not allowed (except
if they are redefined in D). But within package pc this is allowed. Example:
suppose the int attribute att and the int method m() have been defined with
default access in class C of package pc and are not redefined in subclass D
of package pd. The following code :
package pc;
import pd.D;
public class Main{
public static main(String[] argv){
D obj = new D();
System.out.println(obj.att);
System.out.println(obj.m());
System.out.println(((C)obj).att);
System.out.println(((C)obj).m());}
is sucessfully compiled (jdk 1.02 and JDK 1.1 beta2) because obj.att and
obj.m() are considered as legal references to an attribute and a field of D,
as from package pc the inherited attribute and method are visible. This
violates encapsulation. Only ((C)obj).att and ((C)obj).m should be
acceptable references in this case.
Dyade ###@###.###
======================================================================
- duplicates
-
JDK-4028226 in JDK 1.1 beta3 the correction of compiler bug 4023931 is not correct!
-
- Closed
-