Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 216898

Summary: [quick fix] QuickFix proposes wrong visibility for overriding/overridden method
Product: [Eclipse Project] JDT Reporter: Berthold Daum <berthold.daum>
Component: UIAssignee: rgra Missing name <rgransberger>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: Brian.Miller, daniel_megert, eclipse, Lars.Vogel, martinae, matveev, rgransberger
Version: 3.3.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Increase visibility if overriding method is private none

Description Berthold Daum CLA 2008-01-29 08:10:03 EST
Build ID: M20070921-1145

Steps To Reproduce:
1. Create a class A1:
public abstract class A1 {

	protected abstract void m1();
}
2. Create a class B1
public class B1 extends A1 {

	private void m1() {
	}

}
3. Click the QuickFix. The QuickFix proposes to downgrade the visibility of A1.m1() to private. This conflicts with the abstract nature of A1.m1(). Instead it should propose to upgrade the visibility of B1.m1() to protected.


More information:
Comment 1 Chris West (Faux) CLA 2009-07-29 04:39:26 EDT
Similarly, 

package somepackage;

public abstract class Abs {
      abstract String getName();
}


---

package notpackage;

public class AbsImpl extends somepackage.Abs {
    String getName() {
      return "name";
    }
}

---

...'s quickfix on AbsImpl#getName() offers to "Change visibility of Abs.getName() to 'default'", which is obviously incorrect, as that's it's current visibility.
Comment 2 Deepak Azad CLA 2012-04-23 01:13:05 EDT
*** Bug 271551 has been marked as a duplicate of this bug. ***
Comment 3 rgra Missing name CLA 2012-08-18 14:15:05 EDT
Created attachment 220032 [details]
Increase visibility if overriding method is private

Please find along a patch which will fix the bug by using the visibility of the overridden method if the overriding method is private instead of proposing to set the overridden method to private.
Comment 4 Dani Megert CLA 2012-08-28 06:02:19 EDT
Thanks for the patch. It fixes comment 0 but not comment 1, which is also reported in bug 65876. In addition there exist similar problems like e.g. bug 87239. I think a fix should be more general and address all those cases once and for all.

Comment on the patch: the new variable 'overriddenMethodCU' is a bit overkill and makes the patch bigger than needed.
Comment 5 rgra Missing name CLA 2012-08-28 06:27:13 EDT
Thx for your feedback, Daniel. I will have a look at it later. If you have any other bugs in mind which you think can be fixed additionally to this here in one go, please post them. I will do a search later too, but I might miss some.
Comment 6 Dani Megert CLA 2012-09-04 10:42:21 EDT
(In reply to comment #5)
> Thx for your feedback, Daniel. I will have a look at it later. If you have
> any other bugs in mind which you think can be fixed additionally to this
> here in one go, please post them. I will do a search later too, but I might
> miss some.

Search for "[quick fix] visibility" in bugzilla (JDT UI component).
Comment 7 rgra Missing name CLA 2012-11-20 11:45:14 EST
Should I open a new bug when fixing more than one of these visibility bugs to group them underneath?
Comment 8 Dani Megert CLA 2012-11-20 11:50:03 EST
(In reply to comment #7)
> Should I open a new bug when fixing more than one of these visibility bugs
> to group them underneath?

You can make a so-called root bug which depends on those that you plan to fix.
Comment 9 Dani Megert CLA 2013-03-12 08:27:27 EDT

*** This bug has been marked as a duplicate of bug 394692 ***