Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6533652

javac allows to override a final method with a bridge

XMLWordPrintable

    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b06)
      Java HotSpot(TM) Client VM (build 1.7.0-ea-b06, mixed mode, sharing)

      java version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b05)
      Java HotSpot(TM) Server VM (build 1.6.0_01-b05, mixed mode)


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

      A DESCRIPTION OF THE PROBLEM :
      When a bridge is created, javac doesn't check if there is no final method that the bridge will override.

      The compiler should emit an error because there is no way to create the bridge method.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile the code and run it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code should not compile.
      ACTUAL -
      It compiles and raises a verify error at runtime.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.VerifyError: class BridgeMyWorld$Oups overrides final method compareTo.(Ljava/lang/Object;)I
              at java.lang.ClassLoader.defineClass1(Native Method)
              at java.lang.ClassLoader.defineClass(Unknown Source)
              at java.security.SecureClassLoader.defineClass(Unknown Source)
              at java.net.URLClassLoader.defineClass(Unknown Source)
              at java.net.URLClassLoader.access$000(Unknown Source)
              at java.net.URLClassLoader$1.run(Unknown Source)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(Unknown Source)
              at java.lang.ClassLoader.loadClass(Unknown Source)
              at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
              at java.lang.ClassLoader.loadClass(Unknown Source)
              at java.lang.ClassLoader.loadClassInternal(Unknown Source)
              at BridgeMyWorld.main(BridgeMyWorld.java:15)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      public class BridgeMyWorld {
          public final int compareTo(Object o) {
            return 0;
          }
          
          static class Oups extends BridgeMyWorld implements Comparable<Oups> {
              public int compareTo(Oups o) {
                return 0;
              }
          }
          
          
          public static void main(String[] args) {
              Oups oups=new Oups();
              
          }
      }

      ---------- END SOURCE ----------

            mcimadamore Maurizio Cimadamore
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: