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

Using public field of non-public interface from another package is permitted.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.0.2
    • tools
    • sparc
    • solaris_2.4



      Name: vsC45997 Date: 10/15/96


      The section "6.6.1 Determining Accessibility" of The Java Language
      Specification contains the following:

      "If a class or interface type is declared public, then it may be accessed by any Java code that can access the package in which it is declared. If a class or interface type is not declared public, then it may be accessed only from within the package in which it is declared.

      A member (field or method) of a reference (class, interface, or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:

      If the member or constructor is declared public, then access is permitted. All members of interfaces are implicitly public."


      Compiler (or Verifier) permits to use public fields of non-public interface from another package. The test below is failed by harness under dev-jdk1.0.2-wrapper and under dev-jdk1.0.2.

      > javac -d . name05601c.java
      > javac -d . name05601.java
      > java -verify javasoft.sqe.tests.lang.name056.name05601.name05601
      failed


      --------------------------name05601c.java------------------------------
      package javasoft.sqe.tests.lang.name056.name05601.pckg027a;
      public class name05601c {
          public name05601c (int c) {
             n1 = c;
             nd = new name05601d (c);
          }
          public int n1;
          public name05601d nd;
      }
      class name05601d implements name05601j {
          name05601d (int c) {
             n2 = c+i2;
          }
          public int n2;
      }
      interface name05601j {
          int i2 = 6;
      }
      -----------------------------------------------------------------
      --------------------------name05601.java-----------------------------
      package javasoft.sqe.tests.lang.name056.name05601;
      import java.io.PrintStream;
      import javasoft.sqe.tests.lang.name056.name05601.pckg027a.name05601c;
      public class name05601 {
        public static void main(String argv[]) {
           System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
        public static int run(String argv[],PrintStream out) {
           int a;
           boolean notpass = false;
           name05601c d = new name05601c (3);
           try {
              a = d.nd.i2;
              notpass = true;
           }
           catch (Error ee) {
              out.println (ee);
           }
           if ( notpass )
           {
              out.println("failed");
              return 2;
           }
           return 0;
        }
      }
      -----------------------------------------------------------------

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

            tturnidgsunw Todd Turnidge (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: