Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340635 - Types#erasure() doesn't return the raw type.
Summary: Types#erasure() doesn't return the raw type.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 major with 1 vote (vote)
Target Milestone: 4.6 M1   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-22 06:16 EDT by Kevin Pollet CLA
Modified: 2015-08-05 07:21 EDT (History)
5 users (show)

See Also:


Attachments
A workspace with an annotation processor to reproduce the bug (17.86 KB, application/zip)
2011-03-22 06:26 EDT, Kevin Pollet CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Pollet CLA 2011-03-22 06:16:52 EDT
Build Identifier: 20110301-1815

Currently, the Types#erasure() method doesn't return the erased type. If a generic type is given as a parameter the raw type isn't returned. 

For example, if the generic type is something like MyClass<String> the erased type is MyClass<T> and not the raw type MyClass (which is the return of the Oracle implementation of JSR 269).


Reproducible: Always
Comment 1 Kevin Pollet CLA 2011-03-22 06:26:59 EDT
Created attachment 191662 [details]
A workspace with an annotation processor to reproduce the bug
Comment 2 Philipp Wendler CLA 2014-04-12 13:02:09 EDT
This bug still exists with Eclipse 4.3.2 on Linux. Is this going to be fixed?
Comment 3 Jay Arthanareeswaran CLA 2014-04-14 01:09:36 EDT
The Types.erasure() simply invoked ReferenceBinding#erasure() and the TypeBinding returned by ReferenceBinding#erasure() includes the type variables. And since this type binding is generic, DeclaredType#getTypeArguments() returns the type variables. In other words, MyClass<T> is expected output with the code.

And the Javadoc of Types#erasure() simply states: "Returns the erasure of a type"

Srikanth, can you please confirm?
Comment 4 Csaba Kozák CLA 2015-05-08 12:56:38 EDT
This is indeed a problem. "Type erasure is a mapping from types (possibly including parameterized types and type variables) to types (that are never parameterized types or type variables)."

https://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.6

In javac, erasure() returns the erased type correctly, for example

List<T> -> List
List<String> -> List

However in Eclipse:

List<T> -> List<T>
List<String> -> List<T>

This causes problems for annotation processors who are relying on the correct behavior (specified by the the JLS).
Comment 5 Jay Arthanareeswaran CLA 2015-05-11 04:27:55 EDT
Sasi, can you please respond to my question from comment #3? We basically need to replace the erasure() calls inside TypesImpl#erasure() with something that will give us the binding without the type parameter/argument.
Comment 6 Sasikanth Bharadwaj CLA 2015-05-11 06:43:24 EDT
(In reply to comment #5)
> Sasi, can you please respond to my question from comment #3? We basically need
> to replace the erasure() calls inside TypesImpl#erasure() with something that
> will give us the binding without the type parameter/argument.
Yes, something like LE.convertToRawType seems to be needed here
Comment 7 Csaba Kozák CLA 2015-06-04 10:00:21 EDT
Sorry for chiming in here, but do you need more info? I just ran into this again, i started to debug my processor and after i realized actually JDT has a bug. :S
Comment 8 Jay Arthanareeswaran CLA 2015-06-05 00:02:51 EDT
Will look at this for 4.6.
Comment 9 Eclipse Genie CLA 2015-07-27 08:40:06 EDT
New Gerrit change created: https://git.eclipse.org/r/52615
Comment 11 Jay Arthanareeswaran CLA 2015-07-27 22:32:56 EDT
Fixed now.
Comment 12 Sasikanth Bharadwaj CLA 2015-08-05 07:21:03 EDT
Verified for 4.6 M1 using I20150804-2000 build