Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333011 - [compiler] Eclipse compiles codes which javac rejects: incompatible types
Summary: [compiler] Eclipse compiles codes which javac rejects: incompatible types
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6.1   Edit
Hardware: PC All
: P3 normal with 3 votes (vote)
Target Milestone: 4.9 M2   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-21 08:12 EST by Robert Munteanu CLA
Modified: 2018-07-31 15:25 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Munteanu CLA 2010-12-21 08:12:31 EST
The following class compiles in Eclipse:

bc. 
public class Example {
	public static void doSomething() {
		DoJobMr bean = getOnlyElement(new ArrayList());
	}
	public static <T> T getOnlyElement(Iterable<T> iterable) { 
		return null;
	}
	public static class DoJobMr {
	}
}

but it not compiled by javac 1.6.0_22

bc. 
src/Example.java:12: incompatible types
found   : java.lang.Object
required: Example.DoJobMr
                DoJobMr bean = getOnlyElement(new ArrayList());
                                             ^
Comment 1 Ayushman Jain CLA 2010-12-21 08:37:28 EST
Srikanth, please investigate. Thanks!
Comment 2 Robert Munteanu CLA 2011-02-01 04:17:44 EST
Is there any chance for this will be considered for 3.7 ? 

The getOnlyElement method signature is copied from the guava ( formerly google collections)  class Iterables, which I assume is in relatively widespread use. Not to mention that it's quite unpleasant to debug why your CI build fails when Eclipse compiles just fine.
Comment 3 Srikanth Sankaran CLA 2011-02-01 04:43:25 EST
I'll see what I can do here -- Thanks.
Comment 4 Mathias Arens CLA 2011-08-18 03:25:16 EDT
There is a similar issue reported in bug 340506
Comment 5 Eclipse Genie CLA 2018-06-29 17:39:51 EDT
New Gerrit change created: https://git.eclipse.org/r/125279
Comment 7 Stephan Herrmann CLA 2018-06-30 06:00:50 EDT
(In reply to Eclipse Genie from comment #6)
> Gerrit change https://git.eclipse.org/r/125279 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=527238d845cdbbd9ba43a82cb6c0f2d5186c00e8

I added a test that demonstrates correct error reporting at 1.8+

Since type inference in 1.7- is a completely different story, I am not planning to 'downport' this behavior, given this bug has been quiet for some years.
Comment 8 Manoj N Palat CLA 2018-07-31 15:25:10 EDT
Verified with Eclipse 4.9 m2 Build id: I20180731-0800