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

javac allows illegal qualified name class_name.instance_field

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: laC46010 Date: 04/15/97



      Java compiler (JDK1.0.2 - JDK1.1.2) allows to access instance field
      using illegal qualified expression of the following kind:

      <class name>.<instance field name>

      JLS (6.5.5.2 Qualified Expression Names, p.96) says:

      "If an expression name is of the form Q.Id, then Q has already been
      classified as a package name, a type name, or an expression name:

      - If Q is a package name, then a compile-time error occurs.
      - If Q is a type name that names a class type (8), then:
            - If there is not exactly one accessible (6.6) member of the
      class type that is a field named Id, then a compile-time error
      occurs.
            - Otherwise, if the single accessible member field is not a class
      variable (that is, it is not declared static), then a
      compile-time error occurs.
      ...
      "

      The following example is successfully compiled though
      compile-time error should be reported for "SUPER.b":

      --------------------------------------
      class SUPER {
      static int a = 1;
      int b = 2;
      }

      public class clss02201 extends SUPER {
      void test() {
      System.out.println(a);
      System.out.println(b);
      System.out.println(SUPER.a);
      System.out.println(SUPER.b); // NOT ALLOWED
      System.out.println(this.a);
      System.out.println(this.b);
      System.out.println(super.a);
      System.out.println(super.b);
      }
      public static void main(String args[]) {
      clss02201 x = new clss02201();
      x.test();
      }
      }

      --------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dstoutamsunw David Stoutamire (Inactive)
              Reporter:
              leosunw Leo Leo (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: