JDK-6399361 : CONFORMANCE: @Override specification and compiler inconsistent
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0,6
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-03-16
  • Updated: 2017-05-16
  • Resolved: 2006-05-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b86Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
@Override indicates that a method declaration is intended to not only override but also implement a method declaration in a superclass.
http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.4.3
-----
abstract class C1 {
    public void m1() {
    }

    public abstract void m2();
}

class C2 extends C1 {
    @Override
    public void m1() {
    }

    @Override
    public void m2() {
    }
}
-----
Please revise the documentation (http://download.java.net/jdk6/docs/api/java/lang/Override.html) or the implementation.
The JLS should explain it more strictly, too.
http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.6.1.4


REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION See http://blogs.sun.com/ahe?entry=override for an informal discussion of alternative solutions.
11-05-2006

EVALUATION Actually, the compiler is correct and the specification is correct. The method C2.m2 overrides the method C1.m2 (and implements it). See JLS3 8.4.8.1, Overriding (by Instance Method). However, the specification is very convoluted and confusing. There are other examples which the compiler does not get right: public interface Test { void m(); } abstract class A implements Test { // m() is inherited from Test } class B extends A { @Override public void m() {} } Since m is a member of A, class B is overriding a method from a superclass. The compiler rejects this program. The best solution to this problem is to change both the compiler and the specification of @Override: * 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 * method declared in a supertype, compilers are required to generate * an error message.
10-05-2006

EVALUATION Perhaps the documentation of Override is wrong. The JLS is unclear in this area and should be clarified.
23-04-2006

EVALUATION The compiler appears to be wrong. However, fixing this might cause compatibility problems so we should consider if the compiler should be fixed or if the JLS should be changed.
16-03-2006