Summary: | [compiler][generics] Javac-warning on vararg missing in Eclipse | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Holger Klene <h.klene> | ||||
Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> | ||||
Status: | VERIFIED FIXED | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | CC: | amj87.iitr, jarthana, Olivier_Thomann | ||||
Version: | 3.7 | Flags: | srikanth_sankaran:
review?
(amj87.iitr) |
||||
Target Milestone: | 3.7 M6 | ||||||
Hardware: | PC | ||||||
OS: | Windows XP | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Holger Klene
2011-02-14 04:16:25 EST
We don't blame the second one, because this is not really using the varargs argument of the constructor. This might be debatable. Srikanth, your call. I don't think this is actually a problem. Our problem was, that the automatic build (using javac) was set to fail, in case of any warnings. As Eclipse didn't show warnings, we were quite surprised to find the build failed next morning. The first fix was to add a @SuppressWarnings("unchecked") ... but now Eclipse was complaining about the superfluous annotation :-( Actually the varargs parameter won't be null ... therefore it really creates an array of length 0. I've posted this report, as I rate the compatibility with the javac compiler higher. But as you say: It can be seen differently. (In reply to comment #2) > Actually the varargs parameter won't be null ... therefore it really creates an > array of length 0. Yes, Also see that in the following program we do emit a warning - so to be consistent I'll see what it would take to fix this. import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; public class GenericsWarning { public static class IteratorChain<T> implements Iterator<T> { public IteratorChain(Collection<? extends T> ... collections) {} public boolean hasNext() { return false; } public T next() { return null; } public void remove() { throw new UnsupportedOperationException(); } public static void main(String[] args) { List<Integer> a = new ArrayList<Integer>(); List<Long> b = new ArrayList<Long>(); List<Double> c = new ArrayList<Double>(); for (Iterator<Number> iter = new IteratorChain<Number>(); iter.hasNext(); ) { Number n = iter.next(); System.out.println(n.intValue()); } } } } Created attachment 188982 [details]
Patch under test
This patch makes eclipse behavior self consistent as well
as consistent with javac.
Passes all tests, Ayush, please review, TIA Released in HEAD for 3.7 M6 Verified for 3.7M6 using build I20110301-1537. |