Bug 298238

Summary: Unresolved import in superclass causes 'Cannot reduce the visibility of the inherited method' in subclass
Product: [Eclipse Project] JDT Reporter: Josh Micich <josh.micich>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: amj87.iitr, jarthana, Olivier_Thomann, srikanth_sankaran, stephan.herrmann
Version: 3.6   
Target Milestone: 3.6 M5   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix none

Description Josh Micich CLA 2009-12-18 20:47:50 EST
Build Identifier: M20090917-0800

When a superclass (e.g. 'Bar') has protected abstract methods and an unresolved import (that doesn't otherwise cause any compiler errors), the overridden methods in the sub-class get a compiler error "Cannot reduce the visibility of the inherited method from Bar", which is quite misleading.

It seems that in this situation, all abstract methods in the superclass get compiled as 'public' regardless of their actual declared visibility.  This can be observed by running code similar to the following:
System.out.println(Modifier.isPublic(Bar.class.getDeclaredMethods()[0].getModifiers()));
 

Reproducible: Always

Steps to Reproduce:
1. Create a superclass with a compilation error:
package example;
import invalid.type.Name;  // only error
public abstract class Bar {
    protected abstract boolean isBaz(); 
}

2. Create a subclass:
package example;
public class Foo extends Bar {
	protected boolean isBaz() {
		return false;
	}
}

3. Build project and observe unexpected compiler error on Foo.isBaz().
Comment 1 Jay Arthanareeswaran CLA 2010-01-03 23:54:26 EST
Olivier,

I happened to look at this bug and I think the issue is with the following code:

org.eclipse.jdt.internal.compiler.ClassFile#addAbstractMethod(AbstractMethodDeclaration, MethodBinding)

This is where we mark the method with errors as public and abstract. However, I am not quite sure why it has to be made public.
Comment 2 Olivier Thomann CLA 2010-01-04 09:03:40 EST
Yes, I believe this is the issue.
Thanks for looking at it. I'll take care of it.
Comment 3 Olivier Thomann CLA 2010-01-06 12:50:30 EST
Created attachment 155431 [details]
Proposed fix
Comment 4 Olivier Thomann CLA 2010-01-06 12:52:32 EST
Released for 3.6M5.
I'll add a regression test for it.
Comment 5 Olivier Thomann CLA 2010-01-06 13:32:12 EST
Added regression test:
org.eclipse.jdt.core.tests.compiler.regression.ProblemTypeAndMethodTest#test104
Comment 6 Ayushman Jain CLA 2010-01-25 07:10:58 EST
Verified for 3.6M5 using build I20100122-0800.
Comment 7 Olivier Thomann CLA 2010-01-25 14:57:08 EST
Verified.