Possible javac bug around final and covariant overrides

David M. Lloyd david.lloyd at redhat.com
Tue Apr 22 13:35:53 UTC 2014

While exploring adding covariant overrides for Buffer classes, it was 
discovered that javac is not making synthetic methods for covariant 
overrides match the finality of the covariant method.

Simple illustration:

   public class Test {
       public Object foo() { return null; }
   public class TestSub extends Test {
       public final String foo() { return null; }

Yields (javap output):

   public class Test {
     public Test();
     public java.lang.Object foo();
   public class TestSub extends Test {
     public TestSub();
     public final java.lang.String foo();
     public java.lang.Object foo(); // <- not final?!

Is there a good reason for this?  Hypothetically it would seem that this 
might prevent HotSpot from modifying calls to the synthetic method to be 
monomorphic.  Is this a legitimate concern?


More information about the compiler-dev mailing list