Bug 88575 - [1.5] treatment of Object.getClass() not API compliant
Summary: [1.5] treatment of Object.getClass() not API compliant
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-19 14:12 EST by Adam Kiezun CLA
Modified: 2005-03-30 23:35 EST (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 Adam Kiezun CLA 2005-03-19 14:12:16 EST
3.1M5a

Object.getClass() is treated specially (bug 58666)
However this leads to the following API problem.

Doc of IMethodBinding.getMethodDeclaration says that for raw and parameterized
methods something special happens, but for others the result is same as reveiver.

Object.getClass() is neither raw nor parameterized, yet 
IMethodBinding.getMethodDeclaration returns a different result.

For example,
class A{
  void f(){ getClass(); }
}

the call to getClass is the Object.getClass method. It's reported as having type
Class<? extends A>. But asking for getmethodDeclaration returns a method,
declared also in Object but with return type Class<? extends Object>

If nothing else, the API should make this special case clear. 

BTW, it's so strange that the java5 people made this one method so strange. It's
declared as Class<? extends Object> and the doc says it actually has a type
depending on the type of the receiver. Yet, Object is not a generic class. This
is so bizarre.
Comment 1 Philipe Mulet CLA 2005-03-20 13:44:41 EST
The method is strictly declared as of type: Class<? extends Object> on the
declaration side. Only the compiler is translating this type on the fly when
this method gets invoked.

Blame the spec.
Comment 2 Adam Kiezun CLA 2005-03-20 13:59:45 EST
the problem is that the results returned by JCORE APIs are inconsistent with
JCORE docs.

The API docs say one thing, and the actual results do another thing. 
Stricly speaking this is an documentation bug. I think the implementation is
allright.
Comment 3 Philipe Mulet CLA 2005-03-20 14:52:28 EST
Ok, we can mention this in the spec.
Comment 4 Olivier Thomann CLA 2005-03-21 14:02:05 EST
Would this be good enough?

	/**
	 * <p>Returns the binding for the method declaration corresponding to this
	 * method binding. For parameterized methods ({@link #isParameterizedMethod()})
	 * and raw methods ({@link #isRawMethod()}), this method returns the binding
	 * for the corresponding generic method. For other method bindings, this
	 * returns the same binding.</p>
	 * 
	 * <p>Note: The only exception is the method
<code>java.lang.Object.getClass&lt;? extends Object&gt;</code>.
	 * When used in code, this method returns the method binding corresponding to its
	 * declaration in <code>java.lang.Object</code>.
	 * </p>
	 *
	 * @return the method binding
	 * @since 3.1
	 */
Comment 5 Philipe Mulet CLA 2005-03-23 15:37:29 EST
what about ?

Note: A noticeable exception is the method Object.getClass() which is
declared to return Class<? extends Object>, but in reality when invoked 
its return gets substituted into Class<? extends R>, where R is the receiver 
type of the method invocation.

jim - can you double check phrasing ?
Comment 6 Jim des Rivieres CLA 2005-03-23 16:21:23 EST
how about ?

Note: The one notable exception is the method <code>Object.getClass()</code>, 
which is declared to return <code>Class&lt;? extends Object&gt;</code>, but 
when invoked its return type becomes <code>Class&lt;? extends 
</code><em>R</em><code>&gt;</code>, where <em>R</em> is the receiver 
type of the method invocation.
Comment 7 Adam Kiezun CLA 2005-03-23 16:35:01 EST
you might want to mention that it is the _static_ type of the receiver, not the
run-time type
Comment 8 Olivier Thomann CLA 2005-03-23 16:37:08 EST
So we would end up with:

Note: The one notable exception is the method <code>Object.getClass()</code>, 
which is declared to return <code>Class&lt;? extends Object&gt;</code>, but 
when invoked its return type becomes <code>Class&lt;? extends 
</code><em>R</em><code>&gt;</code>, where <em>R</em> is the static type of the
receiver of the method invocation, not the runtime type.
Comment 9 Olivier Thomann CLA 2005-03-24 08:13:16 EST
I released this version:

Note: The one notable exception is the method <code>Object.getClass()</code>, 
which is declared to return <code>Class&lt;? extends Object&gt;</code>, but 
when invoked its return type becomes <code>Class&lt;? extends 
</code><em>R</em><code>&gt;</code>, where <em>R</em> is the compile type of the
receiver of the method invocation.
Comment 10 Olivier Thomann CLA 2005-03-30 23:35:13 EST
Verified in 20050330-0500.
I will open a new bug report to improve the formatting of the doc. The note
should be in its own paragraph.