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
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