Bug 107001 - ITypeBinding#getBinaryName() returns java.lang.Object for type variable
Summary: ITypeBinding#getBinaryName() returns java.lang.Object for type variable
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-15 05:55 EDT by Markus Keller CLA
Modified: 2016-08-23 12:37 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2005-08-15 05:55:23 EDT
I20050811-1530

The javadoc of ITypeBinding#getBinaryName() says:
	 * The binary name of a class is defined in the Java Language 
	 * Specification 2nd edition, section 13.1.

It is not clear what should be returned for type variables. Currently, the
method returns java.lang.Object. I would expect to get either null, or the
binary name as defined in JLS3.

No big deal for me right now, just an API glitch.
Comment 1 Olivier Thomann CLA 2005-08-15 10:22:35 EDT
Jim,

Could you please clarify the specs? Once done, I will adjust the implementation.
Comment 2 Olivier Thomann CLA 2007-02-08 22:03:47 EST
In fact according to the spec, null can safely be returned for type variables.
I'll adjust the spec and the implementation. java.lang.Object seems to be wrong anyway.
Comment 3 Olivier Thomann CLA 2007-02-08 22:11:18 EST
I think we should inline the spec with the JLS3 specification that clearly states what the binary name should be for different cases of type variables.
I'll implement the JLS3 specifications.
Comment 4 Olivier Thomann CLA 2007-02-08 22:48:50 EST
My understanding is that binary name for T in:
- class X<T> {} is X$T
- class X {
   <T> void foo() {
     ...
    }
   }
is X$()V$T
- class X {
   <T> X() {
     ...
    }
   }
is X$()V$T

I would have expected the method selector to be part of the binary name, but this is not the case.
Markus, could you please confirm that you end up with the same binary names?
Comment 5 Markus Keller CLA 2007-02-09 13:22:25 EST
(In reply to comment #4)
Looks good to me in that it conforms to the JLS3. But I think the spec is seriously broken here, since binary names are not unique any more (although one could argue that method type variables only make sense in the context of the declaring method, and there, they are still unique).

I guess the creators of J2SE-6 must have implemented this in javax.lang.model.util.Elements.getBinaryName(TypeElement), but I didn't try it out, since AFAICS, the Eclipse APT support for 1.6 is not yet ready.
Comment 6 Olivier Thomann CLA 2007-02-09 13:32:46 EST
I'll try to make some experiments.
Thanks for your reply.
Comment 7 Olivier Thomann CLA 2007-02-09 14:06:04 EST
javax.lang.model.util.Elements.getBinaryName(TypeElement) cannot be applied on type parameters elements.
Comment 8 Olivier Thomann CLA 2007-02-10 21:41:59 EST
Released for 3.3M6.
Markus, let me know if this corresponds to what you expected.
Comment 9 Goktug Gokdogan CLA 2016-08-23 12:37:27 EDT
Per https://docs.oracle.com/javase/specs/jls/se6/html/binaryComp.html#13.1:

"The binary name of a type variable declared by a generic method is the binary name of the type declaring the method, followed by $, followed by the descriptor of the method as defined in the Java Virtual Machine Specification, followed by $, followed by the simple name of the type variable."

This is also true in the latest version of the spec, http://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html#jls-13.1:

"The binary name of a type variable declared by a generic method (§8.4.4) is the binary name of the type declaring the method, followed by $, followed by the descriptor of the method (JVMS §4.3.3), followed by $, followed by the simple name of the type variable.:


So JLS actually defines the name of the method as part of the binary name; since it is missing the API doesn't follow its contract and the generated names are not unique anymore.