Bug 148041 - [compiler][1.5] should issue unchecked warning on cast to Set<X> of Iterator#next () returning X
Summary: [compiler][1.5] should issue unchecked warning on cast to Set<X> of Iterator#...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.3 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-21 10:22 EDT by Maxime Daniel CLA
Modified: 2006-10-31 04:10 EST (History)
0 users

See Also:


Attachments
Proposed patch (9.12 KB, patch)
2006-10-30 12:20 EST, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maxime Daniel CLA 2006-06-21 10:22:34 EDT
Version: 3.2.0
Build id: I20060614-0843

The following source code:

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class X {
	public static void main(String[] args) {
		Set<X> set = new HashSet<X>();
		for (Iterator<X> iterator = set.iterator(); iterator.hasNext();) {
			Set<X> element = (Set<X>) iterator.next(); // warning
		}
	}
}

gets an unchecked warning on the cast with javac 1.5.0_08 and 6.0 b86. Eclipse does not complain.
Arguably, the return type of iterator.next() is X, which cannot be cast to Set<X>.
Note that (boolean) iterator.next() or (Integer) iterator.next() both raise plain errors with javac and eclipse.
All other things being equal, getting X to implement Set<X> silences the unchecked warning raised by javac.
Comment 1 Maxime Daniel CLA 2006-06-21 10:28:18 EDT
See GenericTypeTest#252, which trigerred the bug. (Checked that removing the error on channels does not improve the situation.)
Comment 2 Philipe Mulet CLA 2006-10-09 10:38:18 EDT
Reproduced with HEAD.
Comment 3 Philipe Mulet CLA 2006-10-30 12:18:31 EST
Added GenericTypeTest#test1062-1064
Comment 4 Philipe Mulet CLA 2006-10-30 12:20:38 EST
Created attachment 52944 [details]
Proposed patch
Comment 5 Philipe Mulet CLA 2006-10-30 12:22:20 EST
Released for 3.3M3.
Fixed
Comment 6 David Audel CLA 2006-10-31 04:00:27 EST
Verified for 3.3 M3 using build I20061030-0010
Comment 7 David Audel CLA 2006-10-31 04:10:22 EST
Verified using I20061030-1704 and not I20061030-0010