Bug 313513 - [1.5][compiler] Usage of raw type: exclude "extends something"
Summary: [1.5][compiler] Usage of raw type: exclude "extends something"
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.6 RC4   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-19 08:32 EDT by Marvin Fröhlich CLA
Modified: 2010-06-07 02:27 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marvin Fröhlich CLA 2010-05-19 08:32:28 EDT
Build Identifier: 20090920-1017

If I have a class like this

class C<T extends SomeClass> {}

and I have enabled warnings for "Usage of raw type" and I use the class as follows

#############
C c = getACInstanceFromSomewhere();
#############

a warning will be produced.

I would like to exclude all classes (not to be warned about), that declare a generic type like this.

class C2<T2 extends Something> {}

instead of just

class C3<T3> {}

If I restrict the generic type parameter to subclasses of something, it is clear, that if used untypedly, it is treated as it is typed with <Something> (the base type).

Otherwise people will either not use this warning and will hence miss a lot of potential bugs or will "enrich" the code with <?> parameters or add SupperssWarnings annotations, which doen't make the code better, but eliminates the warning.

Reproducible: Always
Comment 1 Srikanth Sankaran CLA 2010-06-03 01:03:34 EDT
(In reply to comment #0)

[...]

> If I restrict the generic type parameter to subclasses of something, it is
> clear, that if used untypedly, it is treated as it is typed with <Something>
> (the base type).

These matters are dictated by the language specification and the compiler
is not at liberty to treat the raw type C as though it were C<Something>.
Per section 5.1.9 Unchecked Conversion of JLS, an expression of type C
when converted to C<Something>, must generate an unchecked warning. This
is not possible if C were treated to be C<Something> in the first place
as you propose in:

class C<T extends X> {
	C c1 = new C();
	C<X> c = c1;  // MUST generate a warning here.
}

class X {
}

The unchecked warnings indicate potentially serious problems. OTOH
the raw type usage warning is intended for folks who want to generify
their code and need the help of the compiler in locating all places
where raw types are used and as such the situations you cite are
good candidates for the warnings.

Based on project needs, these warnings can be suppressed wholesale or
individual basis using annotations.
Comment 2 Satyam Kandula CLA 2010-06-07 02:27:09 EDT
Verified for 3.6RC4