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

IllegalAccessError not thrown at runtime when access of a static var is changed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P1
    • None
    • 1.4.2_05
    • hotspot
    • x86
    • solaris_2.6

    Description

      This is for JDK1.4.2

      IllegalAccessError not thrown at runtime when access of a static variable
      is changed from public to private
      There are 2 testcases:

      A.java
      =======

      class A {
           public static int y = 1;
           private static int y = 1;

           public static void main(String[] args) {
                 B.printX();
           }
      }

      B.java
      ======
      public class B {
              static int x = A.y;
              static public void printX() {
                      System.out.println(x);
              }
      }


      When you compile with y as public everyhting seems fine.
      But, if you change y to private in A and *recompile A only*, then when you run the program you should see an error as B should not be allowed to access y. Therefore, there seems to be a bug in the JDK.

      According to Java Specification an IllegalAccessError should be thrown :
      http://java.sun.com/docs/books/jls/second_edition/html/execution.doc.html#44524
      http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html#47259

      Attachments

        Activity

          People

            jloizeausunw Jane Loizeaux (Inactive)
            mbankal Mala Bankal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: