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

Inherited method from package private class throws IllegalAccessError

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 1.2.0
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description



      Name: bk70084 Date: 06/26/98


      Prior to jdk1.2beta3 the following code produced:

      java pkg2.TestExtendedClass
      Testing Extended Class

      using jdk1.2beta3:

      java pkg2.TestExtendedClass
      java.lang.IllegalAccessError: try to access class pkg1/PackagePrivateClass from class pkg2/TestExtendedClass
              at pkg2.TestExtendedClass.<init>(TestExtendedClass.java:12)
              at pkg2.TestExtendedClass.main(TestExtendedClass.java:22)

      In your test directory, place the three files at these locations:
      pkg1/PackagePrivateClass.java
      pkg1/ExtendedClass.java
      pkg2/TestExtendedClass.java

      Compile and run with the test directory on your classpath, and you get the above Exception.


      --------------------------------------------------
      the code:
      --------------------------------------------------

      //
      // PackagePrivateClass.java
      //
      package pkg1;

      /**
       * A package-private class
       */
      class PackagePrivateClass
      {
        private String str;

        public PackagePrivateClass(String str)
        {
          this.str = str;
        }

        public void printStr()
        {
          System.out.println(str);
        }
      }

      //
      //ExtendedClass.java
      //
      package pkg1;

      /**
       * Public class that extends a package-private class
       */
      public class ExtendedClass extends PackagePrivateClass
      {
        public ExtendedClass(String str)
        {
          super(str);
        }
      }

      //
      //TestExtendedClass.java
      //
      package pkg2;

      import pkg1.*;

      public class TestExtendedClass
      {
        private ExtendedClass ec;

        public TestExtendedClass(String str)
        {
         // Instantiate a new ExtendedClass object
         ec = new ExtendedClass(str);

         // Call the method printStr() that Extended Class
         // inherits from the PackagePrivateClass
         ec.printStr();
        }

        public static void main(String[] args)
        {
          TestExtendedClass test =
            new TestExtendedClass("Testing Extended Class");
        }
      }
      (Review ID: 34362)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tturnidgsunw Todd Turnidge (Inactive)
              Reporter:
              bklocksunw Brian Klock (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: