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

Bug 382690

Summary: [override method] Wrong visibility on implemented methods from subinterface
Product: [Eclipse Project] JDT Reporter: Alexander Karatarakis <alex.karatarakis>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, deepakazad, lukas.eder, noopur_gupta, Olivier_Thomann
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Alexander Karatarakis CLA 2012-06-14 21:10:30 EDT
Build Identifier: Version: Juno Release Build id: 20120510-1218

We have an interface B extending another interface A and also overrides some methods. If a class implements B and we have eclipse automatically add the unimplemented methods (either through hovering on the class name and selecting "add unimplemented methods" or through Source->Override/Implement methods), then:

- Methods of interface A correctly get the public visibility
- Methods of interface B correctly get the public visibility
- Methods of interface B that override methods of interface A do not get the correct visibility. They have no modifier and obviously the we get an error that we cannot reduce visibility like that. 

Workaround: Manually add the "public" keyword

Reproducible: Always

Steps to Reproduce:
1) Have two interfaces, one extending another:

public interface InterfaceA{
	int methodA();
	int methodB();
}

public interface InterfaceB extends InterfaceA{
	@Override
	int methodB();

	int methodC();
}

2) Create a class that implements that interface and have eclipse automatically add method stubs. The result is:

public class FooClass implements InterfaceB{
	@Override
	public int methodA()
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	int methodB()
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int methodC()
	{
		// TODO Auto-generated method stub
		return 0;
	}
}

Since methodB() does not have the "public" modifier, we get an error. 


PS: You may want to override a method of a super-interface to return a more specific Object type for example. I am aware that in the supplied example we could simply avoid overriding methodB().
Comment 1 Olivier Thomann CLA 2012-06-14 21:19:58 EDT
Move to JDT/UI
Comment 2 Dani Megert CLA 2012-06-15 02:16:28 EDT
Probably a bug in StubUtility2.createImplementationStub().
Comment 3 Noopur Gupta CLA 2013-06-26 06:04:15 EDT

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