Bug 485135 - "Method does not override a package visible method" should also apply to private methods
Summary: "Method does not override a package visible method" should also apply to priv...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: bugday, helpwanted
Depends on:
Blocks:
 
Reported: 2016-01-04 07:34 EST by Mickael Istria CLA
Modified: 2016-01-05 23:06 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mickael Istria CLA 2016-01-04 07:34:39 EST
With the "Method does not override a package visible method" warning on, I would expect the following piece of code to show a warning on Extend.method() definition:

public class Base {
  private void method() {}
}

public class Extend extends Base {
  void method() {}
}
Comment 1 Mickael Istria CLA 2016-01-04 07:35:24 EST
This is item 13 of http://wheredatapp.com/blog/2015/11/19/why-intellij-idea-is-better-than-eclipse
Comment 2 Stephan Herrmann CLA 2016-01-04 11:03:07 EST
(In reply to Mickael Istria from comment #0)
> With the "Method does not override a package visible method" warning on, I
> would expect the following piece of code to show a warning on
> Extend.method() definition:

Except that Base.method() is not package visible.

=> The label and semantics of the option would need to be *changed*.

Generally, I'd say, this is what @Override is for. It faithfully reports every failed attempt to override, and also helps for documentation.
Comment 3 Mickael Istria CLA 2016-01-04 11:08:55 EST
(In reply to Stephan Herrmann from comment #2)
> Except that Base.method() is not package visible.
> => The label and semantics of the option would need to be *changed*.

Ok, so it would most likely be another check then? If so, I let you update the title to something more appropriate.

> Generally, I'd say, this is what @Override is for. It faithfully reports
> every failed attempt to override, and also helps for documentation.

I agree that @Override is the best way to go. But IDEs are not only for good developers, so we can easily imagine some of Eclipse IDE users not using @Override where they should. Also, there is the case of a user overriding the parent private method by mistake: since the private method is not visible in the scope of their development, users can easily create a new method with same name and face potential issue later, if the method in parent becomes package-public or protected.
That's why a warning could tell: "You're creating a method with same name as a private method already existing in class hierarchy. It's recommended to use a different name."