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

Accesability/Visibility for classes in unnamed package is broken or confusing.

XMLWordPrintable

    • sparc
    • solaris_2.5

      Below are some compilations using the JDK Beta compiler. I read the latest language spec available to me (1.0 Beta, Oct 30) and I didn't see a clear explanation, but, I think that case (3) is showing a compiler bug. It could also be that (2) and (4) are showing compiler bugs. Or that the language spec is incorrect, and the language semantics are inuntuitive.

      - eduardo


      calterra% javac One.java
      calterra% javac pkg/Two.java
      pkg/Two.java:3: Class pkg.One not found in type declaration.
        One a;
             ^
      1 error
      calterra% javac pkg/Three.java
      calterra% javac pkg/Four.java

      Source files are below.

      (1) The first program is legal, and the compiler does the right thing.

      (2) The second source has a bug: class One is not visible outside
      of its package (which is the unnamed package).

      (3) This program is actually incorrect as far as I understand the
      language rules: One is not visible, so the use of One.i should be
      illegal.

      (4) This program is legal, and the compiler does the right thing.

      So, unless I notice something I missed, I intend to file a bug
      for case (3).

      - eduardo

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


      calterra% cat One.java
      public class One {
        public static final int i = 4;
      }

      calterra% cat pkg/Two.java
      package pkg;
      class Two {
        One a;
      }

      calterra% cat pkg/Three.java
      package pkg;
      class Three {
        int k = One.i;
      }

      calterra% cat pkg/Four.java
      package pkg;
      import One;
      class Four {
        One a;
      }

            tturnidgsunw Todd Turnidge (Inactive)
            epelegrisunw Eduardo Pelegrillopart (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: