-
Bug
-
Resolution: Unresolved
-
P5
-
8
This behavior has been around since bridge methods were first used (javac 5), but it's a bug: a bridge method may "accidentally" override a package-access method, changing overriding behavior.
-----
package a; public interface I { public Object m(); }
package a; public class A { /*package*/ Object m() { return "a"; } }
package b; public class B extends a.A { public String m() { return "b"; } }
package a; public class C extends b.B implements I {}
Test:
a.A a = new a.C(); System.out.println(a.m()); // expected: "a"; actual: "b"
-----
Per JLS 8.4.8.1, B.m does not override A.m, and so when A.m is invoked, B.m should not be selected (15.12.4.4). That works correctly _until_ C implements an interface that happens to declare a method with the same descriptor as A.m. Because then a bridge method will be generated, and the bridge method _does_ override A.m.
-----
package a; public interface I { public Object m(); }
package a; public class A { /*package*/ Object m() { return "a"; } }
package b; public class B extends a.A { public String m() { return "b"; } }
package a; public class C extends b.B implements I {}
Test:
a.A a = new a.C(); System.out.println(a.m()); // expected: "a"; actual: "b"
-----
Per JLS 8.4.8.1, B.m does not override A.m, and so when A.m is invoked, B.m should not be selected (15.12.4.4). That works correctly _until_ C implements an interface that happens to declare a method with the same descriptor as A.m. Because then a bridge method will be generated, and the bridge method _does_ override A.m.
- relates to
-
JDK-8009690 javac misses cases for 8.4.8.3 signature erasure clash check
- Open
-
JDK-8010681 Adjust 8.4.8.3 erased signature check for subsignatures
- Open