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

Field protection checking needed at runtime?

    XMLWordPrintable

Details

    • 1.0alpha
    • sparc
    • solaris_2.4
    • Not verified

    Description

      Suppose I change a public ivar in a superclass to private. The
      subclass access to the ivar at runtime will still be allowed. The
      AccessCheck() routine is only implemented in the compiler.

      For instance, consider the following files
      bug133a.java --------------------
      package bug133package;
      public class bug133a {
              public int v = 3;
      }

      bug133.java --------------------
      class bug133 extends bug133package.bug133a {
          public int readV(){
              return v;
          }

          public static void main( String x[] )
          {
              bug133 b = new bug133();
              System.out.println( b.readV() );
          }
      }
      -------------------------------
      Compile them and run.
      ganymede% javac -d . bug133a.java
      ganymede% javac bug133.java
      ganymede% java bug133
      3

      So far, so good. Now I change bug133package.bug133a.v to private,
      recompile that file and re-run.

      ganymede% javac -d . bug133a.java
      ganymede% java bug133
      3

      The subclass still accesses the now-private superclass member.

      Of course, recompiling the subclass gets an error, AS IT SHOULD.
      ganymede% javac bug133.java
      bug133.java:3: Variable v in class bug133package.bug133a not accessible from class bug133.
              return v;
                     ^
      1 error

      Attachments

        Activity

          People

            fyellinsunw Frank Yellin (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: