Bug 91355

Summary: Overriding method in base class with covariant return type fails with AbstractMethodError
Product: [Eclipse Project] JDT Reporter: Daniel R Somerfield <dsomerfi>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Test Case for bug 91355 none

Description Daniel R Somerfield CLA 2005-04-13 18:38:59 EDT
"A" extends "B". "A" implements "I". "C" implements "I2". "I" has a method with
the signature "public I2 doSomething()". B has a method with the signature
"public C doSomething()". Due to the covariant return type, B should fulfill the
contract for A. Indeed, the compiler thinks so, too. However, the following call
will fail with an AbstractMethodError:

I impl = new A();
impl.doSomething();

This is easier to show with sample code. Attached.
Comment 1 Daniel R Somerfield CLA 2005-04-13 18:40:06 EDT
Created attachment 19889 [details]
Test Case for bug 91355
Comment 2 Kent Johnson CLA 2005-04-14 11:23:40 EDT
Daniel, can you please double check the testcase.

I do not get an AbstractMethodError, but the testcase also does not include 
any senders of the method doSomething()
Comment 3 Daniel R Somerfield CLA 2005-04-14 12:59:54 EDT
The I.doSomething() below is just an explanation. In the example, the method of
note is ISourceInterface.get(). If I run TestMain, compiled with javac, it exits
normally. If I run it from eclipse, I get:

Exception in thread "main" java.lang.AbstractMethodError:
test.SourceImpl.get()Ltest/IReturnInterface;
	at test.TestMain.main(TestMain.java:19)

If I look at the generated class files, the one compiled with javac includes two
methods:
"<init>" with the signature "()V" and
"get" with the signature "()test/IReturnInterface;"

with the JDT it only has this:

"<init>" with the signature "()V"

Comment 4 Kent Johnson CLA 2005-04-14 13:18:56 EDT
What build are you running?

I can run the testcase fine & if I change AbstractSource to:

public abstract class AbstractSource {
	public ReturnImpl get() {
		System.out.println("AbstractSource.get()");
		return new ReturnImpl();
	}
}

I get "AbstractSource.get()" printed from both javac & Eclipse.
Comment 5 Daniel R Somerfield CLA 2005-04-14 20:10:47 EDT
I was running on M4. It appears to be ok in M6. Sorry for the bother.