FULL PRODUCT VERSION :
java full version "1.8.0_60-b27"
ADDITIONAL OS VERSION INFORMATION :
Darwin x86_64
A DESCRIPTION OF THE PROBLEM :
To work around JDK-6342411, javac emits "accessibility" bridges when public methods are inherited from non-public superclasses into public derived classes.
Accessibility bridges are not emitted for defender methods, leading to spurious java.lang.IllegalAccessException when those methods are invoked reflectively on the derived class.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Test.java pkg/A.java pkg/B.java
java Test
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected the program to print "hi".
ACTUAL -
The program failed with an IllegalAccessException.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IllegalAccessException: Class Test can not access a member of class pkg.A with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
at java.lang.reflect.Method.invoke(Method.java:490)
at Test.main(Test.java:3)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
=== pkg/A.java
package pkg;
interface A {
default public void f() {
System.err.println("hi");
}
}
=== pkg/B.java
package pkg;
public class B implements A {}
=== Test.java
class Test {
public static void main(String[] args) throws Exception {
Class.forName("pkg.A").getMethod("f").invoke(new pkg.B(), new Object[]{});
}
}
===
---------- END SOURCE ----------