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

Bug 471595

Summary: Unexpected "Type mismatch: cannot convert" message that javac (including 1.9.0-ea-b70) does not produce
Product: [Eclipse Project] JDT Reporter: Geir Helleloid <geir.helleloid>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: stephan.herrmann
Version: 4.5   
Target Milestone: 4.5.1   
Hardware: PC   
OS: Mac OS X   
Whiteboard: To be verified for 4.6 M6

Description Geir Helleloid CLA 2015-07-01 10:08:17 EDT
This code:

public class TestClass {
  public static final <T> 
      java.util.stream.Collector<T, ?, java.util.Optional<T>> findOnly() {
    return java.util.stream.Collectors.collectingAndThen(
        java.util.stream.Collectors.toList(),
	list -> list.size() == 1 
            ? java.util.Optional.of(list.get(0)) 
            : java.util.Optional.empty()
    );
  }
}

compiles with javac 1.8.40, javac 1.9.0-ea-b70, and Eclipse 4.4, but it fails to compile in Eclipse 4.5.0 build 20150621-1200 with the error message

Type mismatch: cannot convert from Collector<Object,capture#18-of ?,Object> to Collector<T,?,Optional<T>>

I thought this was an instance of bug 469653 until I found that javac 1.9.0-ea-b70
compiled it successfuly (unlike in bug 469653).
Comment 1 Stephan Herrmann CLA 2016-03-06 17:51:56 EST
I can reproduce using 4.5.0.

This bug has been fixed via Bug 469753 (4.6M1 & 4.5.1). The fix has later been improved via Bug 487746 (4.6 M6).

*** This bug has been marked as a duplicate of bug 469753 ***