Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 520916

Summary: [1.8][inference] Contrived Generics Fails to Compile
Product: [Eclipse Project] JDT Reporter: Michael D <git>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 4.7   
Target Milestone: 4.8 M2   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Failing class none

Description Michael D CLA 2017-08-12 23:09:51 EDT
Created attachment 269820 [details]
Failing class

The attached class fails to compile using ECJ, but will compile file with OpenJDK 1.8.0_131.

I have tested JDT 3.13.0.v20170614-0247 (https://repo.eclipse.org/content/groups/eclipse/org/eclipse/jdt/org.eclipse.jdt.core/3.13.0.v20170614-0247/)
and M20170301-0400 (http://search.maven.org/#artifactdetails%7Corg.eclipse.jdt%7Corg.eclipse.jdt.core%7C3.12.3%7Cjar).

Thanks

Error:


:[16] The method concat(Iterator<? extends T>, Iterator<? extends T>) in the type Test is not applicable for the arguments (Iterator<Test>, Iterator)
Comment 1 Michael D CLA 2017-08-12 23:11:41 EDT
NB: An older version of ECJ (http://search.maven.org/#artifactdetails%7Corg.eclipse.tycho%7Corg.eclipse.jdt.core%7C3.11.1.v20150902-1521%7Cjar) compiles this class successfully.
Comment 2 Stephan Herrmann CLA 2017-08-13 05:10:18 EDT
Thanks I can reproduce assuming you are compiling at compliance 1.8.

Accepted by ecj versions up-to 4.6M5, rejected since 4.6M6.
More specifically, the fix for bug 488649 causes this change.

Linked from that bug I see the following related bug against javac: https://bugs.openjdk.java.net/browse/JDK-6791481
This 8 year old bug has not been resolved, not even scheduled for resolution as of today.
A newer bug linked from the latter is https://bugs.openjdk.java.net/browse/JDK-8135087 scheduled for Java 10.

From this it's not obvious which behavior is actually correct per JLS. I'm leaning towards saying the new ecj behavior is correct. I will re-asses after javac has fixed their known bug.

To demonstrate the connection to the javac bug, see that this succeeds in ecj:
    concat( array( new Test[ 0 ] ), this.<ITest>method( (Iterable) list ) );
(this is still not recommended coding style).


How to resolve: change the cast from
  (Iterable) list
to
  (Iterable<ITest>) list

This still gives an "unchecked" warning but that is unavoidable in Java, it seems.


Closing (bug is in javac, not ecj) until we see evidence that ecj is indeed at fault.


PS: 
Seeing raw types in the example, I should say that (a) type inference involving raw types is a very thorny issue, and (b) improving support for raw types is not a priority for me personally - for further reference see http://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.8 - search for "The use of raw types".