Bug 154029 - [1.5][compiler] Strange compiler warning "A generic array of ... is created for a varargs parameter"
Summary: [1.5][compiler] Strange compiler warning "A generic array of ... is created f...
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.3 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-16 04:49 EDT by Markus Keller CLA
Modified: 2007-05-07 09:06 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2006-08-16 04:49:31 EDT
I20060815-0800

Arrays.asList(1, "X");

The warning is: "Type safety : A generic array of Object&Comparable<?>&Serializable is created for a varargs parameter"

- I don't see a type safety problem, since the only "genericity" in the array type is Comparable<?>, but 'new Comparable<?>[] {1, "X"}' also doesn't trigger a warning.
- There's a space too much between "Type safety" and ":"
- "Object&Comparable<?>&Serializable" would be easier to read if there were spaces around the "&". The innovative rendering of the warning in the status bar is bug 78746.
Comment 1 Philipe Mulet CLA 2006-11-10 04:38:20 EST
Re: spaces around '&' in intersection type
It may confuse readers since they wouldn't see an intersection type as one piece, but as multiple fragments... 

Re: type safety issue
This behavior is described in the spec I think. Need to double check on this.
Comment 2 Philipe Mulet CLA 2007-03-27 11:58:05 EDT
Tim, pls have a look at it.
Comment 3 Philipe Mulet CLA 2007-05-04 10:20:28 EDT
Javac doesn't report the warning, but technically I think it should. An intersection type isn't reifiable, though it seems to treat it as such.

Comparable<?>[] is tolerated by the spec as an unbound parameterized type (but this is an exception).
Comment 4 Philipe Mulet CLA 2007-05-04 11:07:26 EDT
As per JLS4.7, an intersection type isn't reifiable, and should thus be warned against for varargs invocations.

Added GenericTypeTest#test1136
Comment 5 Philipe Mulet CLA 2007-05-04 11:08:30 EDT
Closing as invalid. 
Comment 6 Markus Keller CLA 2007-05-07 04:26:36 EDT
Never mind, if I ever need to avoid the unchecked warning, I can always write it like this:

  Arrays.<Comparable<?>>asList(1, "X") // no unchecked warning in ecj or javac

However, it's interesting that both ecj and javac protest against

  Arrays.asList(new ThreadLocal<Runnable>(), new ThreadLocal<Cloneable>());

but accept

  Arrays.<ThreadLocal<?>>asList(
                new ThreadLocal<Runnable>(), new ThreadLocal<Cloneable>());

(probably because inference for the former yields ThreadLocal<? extends Object>).
Comment 7 Philipe Mulet CLA 2007-05-07 09:06:10 EDT
Exactly. I agree this doesn't feel intuitive (blame the spec <g>).