Bug 313536 - [1.5][compiler] Generic type fallback
Summary: [1.5][compiler] Generic type fallback
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 10:47 EDT by Marvin Fröhlich CLA
Modified: 2010-06-07 02:56 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 10:47:59 EDT
Build Identifier: 20090920-1017

Example class:

###########
class C<T extends Something>
{
    public void m( T t ) {}
}
###########

If I enable "Usage of raw type" warnings, the following code will generate a warning.

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

c.m( new Something() );
###########

If I "enrich" the code with question marks to eliminate the warning as follows, the code will be uncompilable.

###########
C<?> c = getACInstanceFromSomewhere();

c.m( new Something() );
###########

This is because Eclipse now assumes the following method signature for method m.

void v(? t)

Sometimes Eclipse will even assume it like this.

void v(null t)

This doesn't make any sense and looks like a bug to me. In the above case using a question mark should make Eclipse assume the base type of the generic argument ('Something'), but not ? or null. If no base type is given, Object should be used.

Reproducible: Always
Comment 1 Srikanth Sankaran CLA 2010-06-02 08:27:27 EDT
(In reply to comment #0)
> Build Identifier: 20090920-1017
> 
> Example class:
> 
> ###########
> class C<T extends Something>
> {
>     public void m( T t ) {}
> }
> ###########
> 
> If I enable "Usage of raw type" warnings, the following code will generate a
> warning.
> 
> ###########
> C c = getACInstanceFromSomewhere();
> 
> c.m( new Something() );
> ###########
> 
> If I "enrich" the code with question marks to eliminate the warning as follows,
> the code will be uncompilable.
> 
> ###########
> C<?> c = getACInstanceFromSomewhere();
> 
> c.m( new Something() );
> ###########
> 
> This is because Eclipse now assumes the following method signature for method
> m.
> 
> void v(? t)

It is not upto the eclipse compiler to assume anything, it has to follow
the java language specifications. The type safety rules related to generics
require a conforming compiler to behave a certain way.

See that in all the above scenarios eclipse behavior matches javac
behavior with -Xlint:unchecked -Xlint:rawtypes options turned on.
(The latter option may require a recent version of javac, probably
of the javac7 pedigree.

> This doesn't make any sense and looks like a bug to me. In the above case using
> a question mark should make Eclipse assume the base type of the generic
> argument ('Something'), but not ? or null. If no base type is given, Object
> should be used.

If you find any instance where eclipse behavior is at odds with javac
behavior or at odds with the language specification, please raise a
bug with suitable test cases. As it stands there is nothing for us
to here.

http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf is a good resource
that explains why many things are the way are.

http://java.sun.com/docs/books/jls/download/langspec-3.0.pdf is the
ultimate specification reference.

(Some would argue that the entire generics thing is one big bug :), but
that is neither here nor there)
Comment 2 Satyam Kandula CLA 2010-06-07 02:56:55 EDT
Verified for 3.6RC4