United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6622385 Accessing protected static methods
JDK-6622385 : Accessing protected static methods

Details
Type:
Bug
Submit Date:
2007-10-26
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
hotspot
OS:
windows_xp
Sub-Component:
runtime
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
hs13 (b01)

Related Reports
Backport:
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Example below throws a runtime exception
Exception in thread "main" java.lang.IllegalAccessError: tried to access method
ab.A.m()V from class c.C
        at c.C.c(C.java:8)
        at D.main(D.java:5)

It compiles and runs w/o exception in jdk 1.5.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
either a compile time error or no error as in jdk 1.5
ACTUAL -
Exception in thread "main" java.lang.IllegalAccessError: tried to access method
ab.A.m()V from class c.C
        at c.C.c(C.java:8)
        at D.main(D.java:5)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package ab;

public abstract class A{
	protected static void m(){
		System.out.println("A.m()");
	}
}
-----------------------------------------------------------------------
package ab;

public abstract class B extends A{
}
-----------------------------------------------------------------------
package c;

import ab.A;
import ab.B;

public class C extends A{
	public static void c(){
		B.m();
	}
}
------------------------------------------------------------------------
import c.C;

public class D {
	public static void main(String [] argv){
		C.c();
	}
}
------------------------------------------------------------------------
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
change a call B.m() to A.m()

Release Regression From : 6
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

                                    

Comments
EVALUATION

Test case confirmed.
                                     
2008-01-03
EVALUATION

The regression occurs in Mustang b70.   The given test case works in b69, and fails in b70.

gzilla[play]% for i in /java/re/jdk/6/promoted/all/{b69,b70} ; do echo $i ; $i/binaries/solaris-sparc/bin/javac $(find . -name \*.java ); $i/binaries/solaris-sparc/bin/java -classpath . D; done
/java/re/jdk/6/promoted/all/b69
A.m()
/java/re/jdk/6/promoted/all/b70
Exception in thread "main" java.lang.IllegalAccessError: tried to access method ab.A.m()V from class c.C
        at c.C.c(C.java:8)
        at D.main(D.java:5)
gzilla[play]%


There were no compiler (java/java/compiler) changes in b70. Period.


This looks related to this java/runtime bug, which *was* fixed in b70.  

4293149 Priv. member accessible if its visibility chgd after class using it is compiled

[[ Of the other fixes in b70, one is java/install, one other is java/runtime but is to do with servlet annotatations, and the rest are java/classes_*. ]]

Refiling against java/java/runtime.
                                     
2008-01-03
EVALUATION

Code in class C can access class B, since B is public. And, code in class C can access B.m because m is declared in A and C is a subclass of A (JLS 6.6.2, JVMS 5.4.4). The crucial point is that m is static, so there is no additional check at compile-time or run-time that the reference to m is through A (m's declaring class) or a subclass.
                                     
2008-01-03
WORK AROUND

Launch java with the -XX:+RelaxAccessControlCheck command-line flag.
                                     
2008-01-04



Hardware and Software, Engineered to Work Together