Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4026584

package-private attributes and methods are inherited outside the

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • tools
    • None
    • sparc
    • solaris_2.5.1



      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 ###@###.###

      ======================================================================

            dstoutamsunw David Stoutamire (Inactive)
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: