Bug 221253 - [1.5][compiler] Bound mismatch when type casting
Summary: [1.5][compiler] Bound mismatch when type casting
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Windows Server 2003
: P3 normal (vote)
Target Milestone: 3.5 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-03 21:47 EST by Yenchiu Ku CLA
Modified: 2009-01-27 05:51 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yenchiu Ku CLA 2008-03-03 21:47:33 EST
Build ID: M20080221-1800

Steps To Reproduce:
Test case below:
package test;

public class TestGeneric< T extends Comparable<T> >
{
  T[] array;
  public boolean equals(Object o)
  {
    if (array.length == ( (TestGeneric<Comparable<T>>) o).array.length)
    {
      return true;
    }
    return false;
  }
}

Error for eclipse 3.3.2 :
Bound mismatch: The type Comparable<T> is not a valid substitute for the bounded parameter <T extends Comparable<T>> of the type TestGeneric<T>

No error for Eclipse 3.3.1.1 M20071023-1652.

No error for javac 1.6.0_03.

More information:
Comment 1 Walter Harley CLA 2008-03-04 01:32:57 EST
Was mis-categorized as APT - changed subcomponent to Core.
Comment 2 Philipe Mulet CLA 2008-04-14 07:05:26 EDT
javac doesn't perform bound checks on cast type !?

public class X<T extends Comparable<T>> {
	T[] array;

	public boolean equals(Object o) {
		X<Comparable<T>> x;
		if (array.length == ((X<Comparable<T>>) o).array.length) {
			return true;
		}
		return false;
	}
}

It only notices the first type inconsistency ("X<Comparable<T>> x;"), not the second one.

>javac X.java -d ..\bin -Xlint
X.java:5: type parameter java.lang.Comparable<T> is not within its bound
                X<Comparable<T>> x;
                            ^
X.java:6: warning: [unchecked] unchecked cast
found   : java.lang.Object
required: X<java.lang.Comparable<T>>
                if (array.length == ((X<Comparable<T>>) o).array.length) {
                                                        ^
1 error
1 warning
Comment 3 Philipe Mulet CLA 2009-01-21 07:24:06 EST
Javac now reports 2 errors on scenario from comment 2 as expected in
Java(TM) SE Runtime Environment (build 1.7.0-ea-b42).
Comment 4 Philipe Mulet CLA 2009-01-21 07:31:43 EST
Added GenericTypeTest#test1442.
Closing as worksforme since our behavior is the expected one (since 3.3.2)
Comment 5 Frederic Fusier CLA 2009-01-27 05:51:53 EST
Verified for 3.5M5 using build I20090127-0100 and JRE 7.0 build 1.7.0-ea-b43