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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 1.0.2
    • Fix Version/s: 1.1
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.1beta3
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Not verified

      Description



      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 class from another package. The test below is passed by harness under dev-jdk1.0.2-wrapper. If I run the test
      by dev-jdk1.0.2, the test is failed.

      > javac -d . name05701c.java
      > javac -d . name05701.java
      > java -verify javasoft.sqe.tests.lang.name057.name05701.name05701
      failed


      --------------------------name05701c.java------------------------------
      package javasoft.sqe.tests.lang.name057.name05701.pckg027a;
      public class name05701c {
          public name05701c (int c) {
             n1 = c;
             nd = new name05701d (c);
          }
          public int n1;
          public name05701d nd;
      }
      class name05701d {
          name05701d (int c) {
             n2 = c;
          }
          public int n2;
      }
      -----------------------------------------------------------------
      --------------------------name05701.java-----------------------------
      package javasoft.sqe.tests.lang.name057.name05701;
      import java.io.PrintStream;
      import javasoft.sqe.tests.lang.name057.name05701.pckg027a.name05701c;
      public class name05701 {
        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;
           name05701c d = new name05701c (3);
           try {
              a = d.nd.n2;
              notpass = true;
           }
           catch (Error ee) {
              out.println(ee);
           }
           if ( notpass ) {
              out.println("failed");
              return 2;
           }
           return 0;
        }
      }
      -----------------------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jrose John Rose
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: