Bug 96713 - [1.5][compiler] Inconsistency with Sun JDK
Summary: [1.5][compiler] Inconsistency with Sun JDK
Status: CLOSED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-25 17:42 EDT by Richard Hyatt CLA
Modified: 2005-06-10 10:44 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Hyatt CLA 2005-05-25 17:42:53 EDT
The following test code will generate a "Bound Mismatch" error when compiled 
under 3.1M7:

public class Test
{
	public static <V extends ValueObject, P extends Persistent<V>> P 
createDataObject( V value )
	{
		// create some type of data object given a value object [code 
ommitted]
		return (P)null;
	}
	
	public static void testCreateDataObject()
	{
		ValueObject v = new AValueObject();
		
		Persistent d = createDataObject( v );
	}

	private interface Persistent<V extends ValueObject>
	{
		public V getValueObject();
	}

	private interface ValueObject
	{
	}

	public static class AValueObject implements ValueObject
	{
	}
	
	public static class ADataObject implements Persistent<AValueObject>
	{
		public AValueObject getValueObject()
		{
			return new AValueObject();
		}
	}
}

But when compiled using javac [Sun Java 1.5.03] with -Xlint:all the following 
warning is issued:

Test.java:13: warning: [unchecked] unchecked conversion
found   : <P>P
required: Test.Persistent
                Persistent d = createDataObject( v );
                                               ^
1 warning


Work-around to this problem is to change the above line to:

Persistent<ValueObject> d = createDataObject( v );

but this should not be required since the unchecked base version will assume 
all implementations of Persistent will extend Persistent<ValueObject>.
Comment 1 Philipe Mulet CLA 2005-05-30 19:10:53 EDT
Reproduced in 3.1rc1
Comment 2 Philipe Mulet CLA 2005-05-30 19:19:01 EDT
Reduced testcase:
public class X {
	public static <V, P extends Persistent<V>> P createDataObject(V value) {
		return null;
	}
	public static void testCreateDataObject(Object v) {
		Persistent d = createDataObject(v);
	}

	private interface Persistent<V> {
		public V getValueObject();
	}
}
Comment 3 Philipe Mulet CLA 2005-06-03 06:17:36 EDT
Problem comes from inference using expected return type which did not perform
substitution of variable (P) upper bound (Persistent<V> --> Persistent<Object>).

Added GenericTypeTest#test710.

Also, the unchecked warning from javac looks like a bug. Inference should figure
P is Persistent<Object>, and this needs no unchecked warning (guessing it infers
raw Persistent instead).

Fixed
Comment 4 Frederic Fusier CLA 2005-06-07 09:55:45 EDT
Verified for 3.1 RC2 using build N20050607-0010 + JDT/Core HEAD
Comment 5 Jerome Lanneluc CLA 2005-06-10 10:44:41 EDT
Verified with I20050610-0010