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

CONFORMANCE:@Override specification and compiler inconsistent 2

    Details

    • Subcomponent:
    • Introduced In Build:
      b86
    • Introduced In Version:
      6
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_03"
      Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
      Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
      This might be a duplicate of 6399361 it is certainly. However, I add it as a new case as it has slightly different trigger case and 1.5 does conform in while 1.6 does not spec.

      According to the published 3th edition JLS the @Override annotation should only be applied to methods to override a method from a super type not from super interfaces. Section 9.6.14 (page 279, pdf 313)

      This case is correctly handled in the jdk1.5 series (08 and 15 tested). However in the jdk 1.6 (03 and 06 tested) this is allowed to compile. See the sample code attached this fails to compile under 1.5 which is correct but the more lenient 1.6 compiler will not complain.

      However, this may no longer be a bug if the specification changed due to the effort in resolving http://bugs.sun.com/view_bug.do?bug_id=6399361.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile attached source with JDK1.6

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Fail to compile with warning
      ACTUAL -
      Source compiles

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public abstract class A {
      protected interface AInterface{
      public void handle();
      }
      }

      public class B extends A{
      public void tester(){

      new AInterface(){
                              // Illegal override annotation compiles in javac 1.6.0
                              // As it "Override" a super interface method but not a super class method
      @Override
      public void handle(){
      System.out.println("printing");
      }
      };
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Do the correct thing yourself and do not add @Override to the implementation.

      Release Regression From : 6
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: