Bug 99437

Summary: Override method on generic type with internal class needs to be qualified
Product: [Eclipse Project] JDT Reporter: Jordi Hernandez <jordihs>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Jordi Hernandez CLA 2005-06-10 14:54:48 EDT
Hi, I'v found the following problem with the eclipse compiler. If you have a
abstract generic class with an inner class and a method that returns an instance
of the inner type, such as: 
public abstract class Foo<T>
{
	protected class SomeObject
	{

	}
	abstract SomeObject getSomeObject();
}
And then you override it normally, implementing the abstract method:
public class Bar extends Foo<Baz>
{
	@Override
	SomeObject getSomeObject()
	{
		// TODO Auto-generated method stub
		return null;
	}
}
What you get is a compilation error that states that the return type of
getSomeObject is incompatible with the superclass method. Earlier versions (at
least up to M4) would report the error in the editor but run the code. Another
thing to note is that when the method is autogenerated in a subclass, an import
to SomeObject is created that automatically renders a compilation warning that
states that SomeObject is never used even if it is. 
To solve the compilation error, you can qualify the return type of the method in
the subclasses, so this: 
	@Override
	Foo.SomeObject getSomeObject()
	{
		// TODO Auto-generated method stub
		return null;
	}
would yield warnings but no errors. 
So it seems that there is a problem with qualification of the inner class. I
might be wrong, but I think such a construct should be legal and it does run
under a version 5 JRE. 
My apologies if a repeated a report, I searched and couldn't find anything
simmilar. Cheers.
Comment 1 Kent Johnson CLA 2005-06-10 15:48:17 EDT
With the latest I do not see any problems with this case:

public abstract class Foo<T> {
	protected class SomeObject {}
	abstract SomeObject getSomeObject();
}
class Bar extends Foo<Baz> {
	@Override SomeObject getSomeObject() { return null; }
}
class Baz {}

Please reopen if you still encounter the problem with a new build or if I 
extracted the testcase incorrectly.
Comment 2 Jordi Hernandez CLA 2005-06-10 16:23:06 EDT
(In reply to comment #1)
> With the latest I do not see any problems with this case:
> 
> public abstract class Foo<T> {
> 	protected class SomeObject {}
> 	abstract SomeObject getSomeObject();
> }
> class Bar extends Foo<Baz> {
> 	@Override SomeObject getSomeObject() { return null; }
> }
> class Baz {}
> 
> Please reopen if you still encounter the problem with a new build or if I 
> extracted the testcase incorrectly.

I tried with RC1. I'll wait until RC2 goes public and retest. 
Thanks a lot.