Bug 234619 - [1.5][compiler] Object#getClass() has wrong expression type binding with JRE from 1.6
Summary: [1.5][compiler] Object#getClass() has wrong expression type binding with JRE ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 211037
  Show dependency tree
 
Reported: 2008-05-29 09:29 EDT by Markus Keller CLA
Modified: 2008-08-28 12:34 EDT (History)
2 users (show)

See Also:
markus.kell.r: review+


Attachments
Proposed patch (3.79 KB, patch)
2008-05-29 12:46 EDT, Philipe Mulet CLA
no flags Details | Diff
Better patch (4.05 KB, patch)
2008-05-29 12:58 EDT, Philipe Mulet CLA
no flags Details | Diff
Patch for 3.3.x (5.04 KB, patch)
2008-05-30 09:05 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2008-05-29 09:29:30 EDT
I20080528-2000

With a JRE from Java 1.6, create an AST for this class:

class TrivialClass {
	void m(Object someObject, Integer intObject) {
		Exception class1 = someObject.getClass();
		Exception class2 = intObject.getClass();
	}
}

Now call resolveTypeBinding() on the MethodInvocations:
- For 'someObject.getClass()', it's 'Class<capture#1-of ?>'.
- For 'intObject.getClass()', it's 'Class<capture#2-of ? extends Integer>'.

I would expect to get 'Class<capture#1-of ? extends Object>' in the first case as well, since JLS3 says: 'The type of a method invocation e.getClass(), where the expression e has the static type T, is Class<? extends |T|>.'

With a 1.5 JRE, the binding is as expected (probably because Object#getClass() had declared return type Class<? extends Object> in 1.5, but Class<?> in 1.6).
Comment 1 Philipe Mulet CLA 2008-05-29 12:30:04 EDT
I would expect this too.
Comment 2 Philipe Mulet CLA 2008-05-29 12:44:31 EDT
Added GenericTypeTest#test1338
Comment 3 Philipe Mulet CLA 2008-05-29 12:46:18 EDT
Created attachment 102685 [details]
Proposed patch
Comment 4 Philipe Mulet CLA 2008-05-29 12:58:21 EDT
Created attachment 102689 [details]
Better patch

Should not discriminate on Object declaring class, since it prevents from ignoring bogus override of Object#getClass()
Comment 5 Philipe Mulet CLA 2008-05-29 12:58:44 EDT
Markus - is this any critical for 3.4 ?
Comment 6 Markus Keller CLA 2008-05-29 13:46:29 EDT
The fix looks good and solves bug 211037 (better than my workaround, which only
prevents the runtime exception). It makes the bindings look the same as with a 1.5 JRE, so I don't expect that any client could have a problem with the fix.

+1 from my side for RC3, but I could also live with the workaround for 3.4.
Comment 7 Philipe Mulet CLA 2008-05-30 05:57:05 EDT
Given it is not super critical, and presence of a workaround, would rather not put it in by the end game rules for RC3.

Will defer it until 3.4.1 (or 3.5).
Comment 8 Philipe Mulet CLA 2008-05-30 07:10:32 EDT
Also added GenericTypeTest#test1339
Comment 9 Philipe Mulet CLA 2008-05-30 09:05:08 EDT
Created attachment 102849 [details]
Patch for 3.3.x
Comment 10 Philipe Mulet CLA 2008-05-30 09:58:18 EDT
Targeting for 3.4.1. 
Also released to 3.3.x maintenance
Comment 11 Philipe Mulet CLA 2008-06-23 12:41:29 EDT
In 3.5 stream, tests are actually GenericTypeTest#test1339 & test1342
Comment 12 Philipe Mulet CLA 2008-06-23 12:56:50 EDT
Ignore comment 11
Comment 13 Philipe Mulet CLA 2008-06-23 12:57:18 EDT
Released for 3.5M1
Comment 14 Philipe Mulet CLA 2008-06-25 11:43:16 EDT
Released to 3.4 maintenance branch
Fixed
Comment 15 Philipe Mulet CLA 2008-06-25 11:48:44 EDT
Released for 3.4.1
Comment 16 Olivier Thomann CLA 2008-08-06 14:26:16 EDT
Verified for 3.5M1 using I20080805-1307
Comment 17 Frederic Fusier CLA 2008-08-28 12:34:06 EDT
Verified for 3.4.1 using build M20080827-2000.