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

protected access not implemented correctly for static protected fields/methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.1
    • tools
    • 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.
      ======================================================================

            tturnidgsunw Todd Turnidge (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: