Bug 81576 - [compiler] Inner class causes problems in subclasses when the class hierarchy is parametrized (generic)
Summary: [compiler] Inner class causes problems in subclasses when the class hierarchy...
Status: RESOLVED DUPLICATE of bug 82349
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-17 20:23 EST by Irfan Adilovic CLA
Modified: 2005-02-03 04:48 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Irfan Adilovic CLA 2004-12-17 20:23:05 EST
Having an inner class in a generic class makes it "problematic" to use that
class in deriving classes. A compile with "javac -Xlint:all *java" yields *no*
warnings or errors.

Below is the code that fully reproduces the problem. Included are also comments
before lines that have errors or warnings (reported from the eclipse's compiler).

SuperType.java:
public class SuperType<T> {
	protected InnerType valueWrapper;
	protected class InnerType {
		private T value;
		protected InnerType(T value) {
			this.value = value;
		}
	}
	public SuperType(T value) {
		/*
		 * This constructor exists only to show that the usage of the inner
		 * class within its enclosing class makes no problems
		 */
		this.valueWrapper = new InnerType(value);
	}
	protected SuperType() {
		// Provided for the convenience of subclasses
	}
}

SubType.java:
public class SubType<T> extends SuperType<T> {

	public SubType(T value) {

		/* The constructor SuperType <T>.InnerType(T) is undefined */
		InnerType localValueWrapper = new InnerType(value);

		/*
		 * Type mismatch: cannot convert from SuperType <T>.InnerType to
		 * SuperType <T>.InnerType
		 * 
		 * Type safety: The expression of raw type SuperType.InnerType is
		 * converted to SuperType <T>.InnerType. References to generic type
		 * SuperType <T>.InnerType should be parametrized.
		 */
		localValueWrapper = super.valueWrapper;
	}

}

Remarks:
Making *everything* public in order to make sure that visibility is not somehow
misinterpreted, yields no difference. In order to show that the problem is
generics-specific, following can be done:

* Introduce a type T (T.java: public class T {})
* Remove all generics-parameters (three occurences of <T>) from the above two files

The compiler(s) (both javac and eclipse's compiler) work(s) perfectly in the
latter scenario.

The problem is rather annoying, as one must externally compile in order to be
sure that there are no problems in the code.

-- Irfy
Comment 1 Irfan Adilovic CLA 2004-12-17 20:43:15 EST
The problem was discovered in Eclipse 3.1M4 under Windows XP with Sun's JDK5.0
(javac 1.5.0-rc). Not tested on any other configuration, but /should/ be
Eclipse-specific, and presumably reproducible on other platforms with this
Eclipse build.

-- Irfy
Comment 2 Philipe Mulet CLA 2005-02-03 04:48:30 EST
Added GenericTypeTest#test492

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