FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Server VM (build 1.5.0_03-b07, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 2.4.9-e.25kmap1enterprise #1 SMP
A DESCRIPTION OF THE PROBLEM :
suppose class A is package private, class B is public and in
the same package as A and extends A, a public method on B
has the signature of foo(A... args).
class C is in a different package, and has an invocation of
foo(new B(), new B())
class C will compile, but the resulting byte code does not run
(gets an java.lang.IllegalAccessError), since javac would
generate a new A[] call for class C for the varargs invocation.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the source code included below,
run it as follows:
java -Xfuture -classpath [classpath pointing to the classfiles] p2.C
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
should fail to compile since p2.C doesn't have access to
p1.A
ACTUAL -
compiler generated no error, but when java is invoked on
the resulting class file (with the -Xfuture option, or if classes
in p2 and p1 are loaded from different file system pathes),
you get a runtime error:
Exception in thread "main" java.lang.IllegalAccessError: tried to access class p1.A from class p2.C
at p2.C.main(C.java:6)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IllegalAccessError: tried to access class p1.A from class p2.C
at p2.C.main(C.java:6)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
A.java
----------
package p1;
class A {
A() {
}
}
------------
B.java
------------
package p1;
import java.io.*;
public class B extends A {
public B() {}
public void foo(A... args) {
System.out.println(args);
}
}
-----------
C.java
----------
package p2;
import p1.B;
public class C {
public static final void main(String[] args) {
(new B()).foo(new B(), new B());
}
}
---------
---------- END SOURCE ----------