Bug 60681 - [1.5] Return type not strict enough
Summary: [1.5] Return type not strict enough
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-01 08:00 EDT by Stefan Matthias Aust CLA
Modified: 2005-01-11 11:02 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Matthias Aust CLA 2004-05-01 08:00:51 EDT
I'm using I20040428 with Cheetah04.  This piece of code is compiled by Cheetah
while javac will issue an "unchecked assignment" warning and needs "new
Vector<T>()" instead.

import java.util.Vector;

public class A {
    <T> Vector<T> valuesOf(Hashtable<?, T> h) {
        return new Vector();
    }
}
Comment 1 Stefan Matthias Aust CLA 2004-05-01 08:13:04 EDT
This might be a similar problem... the code shown below compiles fine with
Eclipse but issues an "[unchecked] unchecked cast to type
java.util.Vector<java.lang.Object>" warning with javac.  In constrast to the
first example, this code looks valid to me...

import java.util.Vector;

public class B {
    Vector<Object> data;
    
    public void t() {
        Vector<Object> v = (Vector<Object>) data.elementAt(0);
    }
}
Comment 2 Philipe Mulet CLA 2004-05-07 18:44:20 EDT
Support added to diagnose unsafe returned value.
Added regression test: GenericTypeTest#test176.

Both testcases are issuing warnings:
----------
1. WARNING in ...\A.java (at line 5)
	return new Vector();
	       ^^^^^^^^^^^^
Unsafe type operation: Should not return value of raw type Vector instead of 
type Vector<T>. References to generic type Vector<E> should be parameterized
----------

----------
1. WARNING in ...\B.java (at line 7)
	Vector<Object> v = (Vector<Object>) data.elementAt(0);
	                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Unsafe type operation: Should not cast from Object to Vector<Object>. Generic 
type information will be erased at runtime
----------


Comment 3 Philipe Mulet CLA 2004-05-07 18:45:00 EDT
Fixed