Bug 223427 - [1.5][compiler] unnecessary warning when creating an array of varargs
Summary: [1.5][compiler] unnecessary warning when creating an array of varargs
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.8 M5   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-20 17:19 EDT by Rémi Forax CLA
Modified: 2012-01-23 05:10 EST (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 Rémi Forax CLA 2008-03-20 17:19:31 EDT
Build ID: I20080207-1530

Steps To Reproduce:
1. compile the snippet

HashSet<Class<?>> constantClassSet=new HashSet<Class<?>>();
Collections.addAll(constantClassSet,
  String.class,       // utf8 symbols
  Integer.class, Float.class, Long.class, Double.class // primitive values
);

More information:
The warning reported by the compiler: 
Type safety : A generic array of Class<? extends Object> is created for a varargs parameter	AnonymousClassLoader.java	kijaro-properties/davinci/bootcp/java/dyn	line 229	Java Problem13

An array of parameterized type is unsafe because a parameterized
type is not a reified type. An array of wildcard type is safe.
The compiler infers Class<? extends Object> but doesn't 'see'
that Class<? extends Object> is equivalent to Class<?>.

Rémi
Comment 1 Rémi Forax CLA 2008-04-21 08:50:41 EDT
Argh, the previous test case doesn't exhibit the problem.
Should be:

HashSet<Class<?>> constantClassSet=new HashSet<Class<?>>();
Collections.addAll(constantClassSet,
  String.class, Object.class
);
Comment 2 Philipe Mulet CLA 2008-04-21 09:07:27 EDT
This equivalence is not accounted in the spec, hence the compiler diagnosis is accurate I believe.

I agree that the underlying bounds are equivalent, but Class<?> is unbound, and benefits from certain privileges wrt to reification where Class<? extends Object>. So unless the spec was to account for it, then we wouldn't be allowed to change this.

Note that javac exhibits the same behavior as we do.
Comment 3 Philipe Mulet CLA 2008-04-21 09:19:52 EDT
Added VarargsTest#test061
Comment 4 Srikanth Sankaran CLA 2012-01-11 03:23:29 EST
Rémi, As you are aware, SE7 adds linguistic support
for this via @SafeVarargs annotation. OK to close
as is for compliance < 1.7 ?
Comment 5 Rémi Forax CLA 2012-01-11 08:45:15 EST
(In reply to comment #4)
> Rémi, As you are aware, SE7 adds linguistic support
> for this via @SafeVarargs annotation. OK to close
> as is for compliance < 1.7 ?

Ok to close.
Philippe was right and could have closed that bug.

cheers,
Rémi
Comment 6 Srikanth Sankaran CLA 2012-01-11 19:49:46 EST
Closing as WONTFIX.
Comment 7 Jay Arthanareeswaran CLA 2012-01-23 05:10:08 EST
Verified for 3.8M5