Bug 192815 - [1.5][compiler] Misleading error message for static methods with @Override annotation
Summary: [1.5][compiler] Misleading error message for static methods with @Override an...
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-15 04:29 EDT by Christoph Nievergelt CLA
Modified: 2008-06-03 10:14 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Nievergelt CLA 2007-06-15 04:29:22 EDT
Static methods cannot be overridden, but only hidden by a derived class.
Therefore the @Override annotation is incorrect for static method in a derived class, even if a static method with the same signature exists in the base class.

Until Eclipse 3.1, this mistake was simply disregarded.
With Eclipse 3.2 (certainly with 3.2.1 and later) this treated as an error, even if the Java compiler (at least Sun's Java 5 compiler) does not treat this as an error. I suspect that the Java 6 compiler is more strict and also think that is OK anyway to mark this as an error.

My issue is that the error message that looks something like this:
"The method xYzzy() of type DerivedClass must override a  superclass method"

If the affected method is static, I suggest to use an error message like this:
"Static method xYzzy() cannot be overridden, but only hidden. Remove @Override annotation."

Alternatively, the @Override annotation could be flagged with an error message like this:
"Static methods cannot be overridden, but only hidden. Remove @Override annotation."
Comment 1 Philipe Mulet CLA 2008-05-07 12:31:40 EDT
On following:

class Base {
	public static void foo() {}
	public void bar() {}
}

public class X extends Base {
	public static void foo() {}
	public void bar() {}
}

Neither javac6 or javac7 will report missing@Override annotation.
Neither do we in 3.4M7.

Comment 2 Philipe Mulet CLA 2008-05-07 12:34:53 EDT
I agree our error message needs to be read twice to figure, but essentially it tells the truth in saying that X#foo() does not override Base#foo() (since static methods do not override).

I think our current message is tolerable.
And yes javac6 and javac7 also report this issue.
Comment 3 David Audel CLA 2008-05-13 06:13:27 EDT
Verified for 3.4RC1.
Comment 4 Christoph Nievergelt CLA 2008-05-24 09:29:16 EDT
My complaint was about the following situation:

class Base {
  public static void xYzzy() {}
}

public class X extends Base {
  @Override
  public static void xYzzy() {}
}

In this situation, the message simply does not make sense.

Sorry for the unclear bug report; I should have included an example when I reported.
Comment 5 Philipe Mulet CLA 2008-06-03 10:14:36 EDT
In theory you could imagine nuancing the error message, but in practice the way it reads today is not wrong; I guess it depends whether you think 'static' is a stronger statement than '@Overrides'.

I wouldn't change the message for such a small nuance.
Closing again.