Bug 298238 - Unresolved import in superclass causes 'Cannot reduce the visibility of the inherited method' in subclass
Summary: Unresolved import in superclass causes 'Cannot reduce the visibility of the i...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 3.6 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-18 20:47 EST by Josh Micich CLA
Modified: 2010-01-25 14:57 EST (History)
5 users (show)

See Also:


Attachments
Proposed fix (4.50 KB, patch)
2010-01-06 12:50 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.