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

protected inner class constructor invoked from subclass in other package

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: laC46010 Date: 03/23/99



      javac (1.1.x, 1.2fcs, 1.2.1) fails to compile inner class instance
      creation expression, if inner class declaration has protected modifier
      and this class is accessed by the class which belongs to the
      different package. If the class belongs to the same package compilation
      succeeds. This bug causes JDK1.2.1 to fail JCK test icls04591m2.html
          The access should be granted in this case because class "test" extends
      class "A", and Inner Classes Specification reads:

      "All the existing access protection and modification modes apply in a
      regular fashion to types which are members of other classes. Classes
      and interfaces can be declared private or protected within their
      enclosing classes."

      Test example and diagnostics follow:
      -------------------------------------------------------
      % cat A.java
      /* A.java */
      package inner;

      public class A {
          protected class B {
          }
      }

      % cat test.java
      /* test.java */
      package pkg;

      import inner.A;

      public class test extends A {
          public static void m() {
              B b = (new A()).new B();
          }
      }
      % java -version
      java version "1.2.1"
      Classic VM (build JDK-1.2.1-K, green threads, sunwjit)
      % javac A.java
      % javac test.java
      test.java:8: No constructor matching A. B(inner.A) found in inner class inner.A. B.
              B b = (new A()).new B();
                             ^
      1 error


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

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

        Attachments

          Activity

            People

            Assignee:
            wmaddoxsunw William Maddox (Inactive)
            Reporter:
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: