JDK-6709448 : CONFORMANCE:@Override specification and compiler inconsistent 2
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2008-06-02
  • Updated: 2011-02-16
  • Resolved: 2008-07-28
Related Reports
Relates :  
Relates :  
Relates :  
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.

Comments
EVALUATION This is not a true regression, as the issue described in this bug is a deliberately wanted side-effect of the fix of CR 639936 made by Peter. As also described in this blog entry http://blogs.sun.com/ahe/?entry=override Peter has put a lot of effort in order to address the problem of override annotation wrt interfaces. It seems that he arrived to the conclusion that the JLS could be improved by changing the paragraph http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.6.1.4 to: "Indicates that a method declaration is intended to override a method declaration in a supertype. If a method is annotated with this annotation type but is not in fact override-equivalent to any visible method declared in a supertype, compilers are required to generate an error message." The current compiler implementation reflects this (virtual) JLS change (the new behavior has been observable since release 6 b86). The community seems to be quite happy with this new improved behavior (I've spent some time reading all the comments in the above blog entry). However it remains true that the current compiler implementation and the JLS do not conform one each other. As also reported in 5008260, this is a deliberate change and it will be documented in the next version of the JLS.
28-07-2008