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

IllegalAccessError is not thrown when a class that was declared public is change

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.4

      Description



      Name: vsC45997 Date: 11/26/96


      If I recompile a class which was public on the previous compilation but
      now it is not public then I cannot obtain IllegalAccessError on JDK 1.1
      if a pre-existing binary is linked that needs but no longer has access
      to the class type. JDK 1.0.2 works OK in this situation and throws the
      needed IllegalAccessError.

      The section "13.4.3 public Classes" of The JLS contains the following:

      "If a class that was declared public is changed to not be declared public,
      then an IllegalAccessError is thrown if a pre-existing binary is linked
      that needs but no longer has access to the class type"

      Therefore, I guess IllegalAccessError must be thrown.

      Lets consider my test on binary compatibility.
      The test consist of three files.

      // FILE: binc00601a.java
      package javasoft.sqe.tests.lang.binc006.binc00601.binc00601b;
      public class binc00601a {
        int a = 5;
      }
          
      // FILE: binc00601.java
      package javasoft.sqe.tests.lang.binc006.binc00601;
      import java.io.PrintStream;
      import javasoft.sqe.tests.lang.binc006.binc00601.binc00601b.binc00601a;

      public class binc00601 {
        public static void main(String argv[])
        {
           System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
        public static int run(String argv[],PrintStream out) {
          binc00601a ncli;
          try {
            ncli = new binc00601a ();
          }
          catch (IllegalAccessError e) {
            out.println (e);
            return 0;
          }
          out.println ("failed");
          return 2;
        }
      }
          
      // FILE: binc00601b.java
      package javasoft.sqe.tests.lang.binc006.binc00601.binc00601b;
      class binc00601a {
        int a1 = 5;
      }
          

      After separate compilations and execution with -verify option we have
      on 1.1 compiler:
      javac -d . binc00601a.java
      javac -d . binc00601.java
      javac -d . binc00601b.java
      novo31% /export/ld32/jdk_1.1M/bin/java -verify javasoft.sqe.tests.lang.binc006.binc00601.binc00601
      failed

      On 1.0.2 compiler we have correct result:

      jdk_1.0.2/bin/javac -d . binc00601a.java
      jdk_1.0.2/bin/javac -d . binc00601.java
      jdk_1.0.2/bin/javac -d . binc00601b.java
      jdk_1.0.2/bin/java -verify javasoft.sqe.tests.lang.binc006.binc00601.binc00601
      java.lang.IllegalAccessError: javasoft/sqe/tests/lang/binc006/binc00601/binc00601b/binc00601a

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              nsaraiyasunw Nakul Saraiya (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: