Bug 328827 - Compiler fails to recognize a Map when using J2SE 1.4 compiler settings
Summary: Compiler fails to recognize a Map when using J2SE 1.4 compiler settings
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.7 M4   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-27 09:49 EDT by Thomas Watson CLA
Modified: 2010-12-07 08:51 EST (History)
5 users (show)

See Also:
Olivier_Thomann: review+


Attachments
test projects (6.12 KB, application/zip)
2010-10-27 09:49 EDT, Thomas Watson CLA
no flags Details
Patch under test (3.55 KB, patch)
2010-10-28 03:11 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Revised patch under test (3.54 KB, patch)
2010-10-28 03:53 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Final patch - passes all JDT/Core tests (3.65 KB, patch)
2010-10-28 07:40 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Watson CLA 2010-10-27 09:49:30 EDT
Created attachment 181835 [details]
test projects

I20101025-1800

This likely is a dup of bug328775.  But the scenario is slightly different so I am opening a separate bug.  As in bug328775 a J2SE 1.4 project is behaving incorrect.

The following block of code causes a compile error in the J2SE 1.4 project when it should not:

	EventProperties props = new EventProperties(null);
	Event event = new Event("test/topic", props);

The issue is the compiler does not think EventProperties is a Map, but it implements Map<String, Object>

The signature of the Event constructor that should be used is:

	public Event(String topic, Map<String, ? > properties)

But the compiler fails to find that constructor for the test.event1 project, which is using J2SE 1.4 compiler settings.  The test.event2 project finds the constructor and is using J2SE 1.5 compiler settings.
Comment 1 Olivier Thomann CLA 2010-10-27 09:55:04 EDT
Srikanth, please investigate.
Comment 2 Olivier Thomann CLA 2010-10-27 11:51:47 EDT
This is caused by the fix for bug 324850.
Srikanth, I think we now need to "filter" some generic information where we didn't need to in the past.
If we cannot "fix" this, we might want to revert bug 324850 for M3 as this is causing grief to OSGI users.
Comment 3 Srikanth Sankaran CLA 2010-10-28 03:11:21 EDT
Created attachment 181907 [details]
Patch under test

This patch fixes the problem. The automated tests are being run
now. Will update status once done.

Basically, the problem is that with hybrid 1.4/1.5+ projects
modes, while establishing type equivalence, the compiler needs
to be prepared for a type such as Map appearing in one of three
distinct forms: 

    (a) As a ParameterizedTypeBinding e.g Map<String, String>
    (b) As a RawTypeBinding (Map#RAW) and finally
    (c) As a BinaryTypeBinding

    When the usage of a type lacks type parameters, whether we land
up with the raw form or not depends on whether the underlying type
was "seen to be" a generic type in the particular build environment
or not. So usages of Map in a 1.4 project don't produce a "raw" type,
as Map is not seen to be a generic type in the first place by the
compiler when found in a 1.4 JRE.
Comment 4 Srikanth Sankaran CLA 2010-10-28 03:53:06 EDT
Created attachment 181911 [details]
Revised patch under test

Patch that avoids applying erasure prematurely.
Under test.
Comment 5 Srikanth Sankaran CLA 2010-10-28 07:40:08 EDT
Created attachment 181920 [details]
Final patch - passes all JDT/Core tests

Same fix as before, with its application tightened.
Comment 6 Srikanth Sankaran CLA 2010-10-28 07:42:31 EDT
Olivier, please review, TIA. We probably need a similar fix
in org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.isEquivalentTo(TypeBinding)

and org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.isEquivalentTo(TypeBinding)

but I'll treat that as a separate case from this bug report.
Comment 7 Olivier Thomann CLA 2010-10-28 08:52:59 EDT
I agree with the principle.
Comment 8 Jay Arthanareeswaran CLA 2010-10-29 07:20:19 EDT
Just verified that build I20101028-1441 does not have this bug.
Comment 9 Olivier Thomann CLA 2010-10-29 12:59:13 EDT
Will you also update the SourceTypeBinding implementation ?
Comment 10 Srikanth Sankaran CLA 2010-11-01 10:46:51 EDT
Released in HEAD for 3.7 M4

(In reply to comment #9)
> Will you also update the SourceTypeBinding implementation ?

Yes, however, I'll follow up on this on a separate defect.
Comment 11 Srikanth Sankaran CLA 2010-11-02 03:56:43 EDT
(In reply to comment #6)
> Olivier, please review, TIA. We probably need a similar fix
> in
> org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.isEquivalentTo(TypeBinding)
> 
> and
> org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.isEquivalentTo(TypeBinding)
> 
> but I'll treat that as a separate case from this bug report.

The latter change is necessitated by and handled in the context of
the fix for bug 186565
Comment 12 Srikanth Sankaran CLA 2010-11-02 04:00:12 EDT
(In reply to comment #11)
> The latter change is necessitated by and handled in the context of
                       ^^^^^^^^^^^^^^^^

I meant to say "needed for".
Comment 13 Ayushman Jain CLA 2010-12-07 08:51:51 EST
Verified for 3.7M4 using build I20101205-2000.