Bug 501128

Summary: Type inference with lambdas & CompletableFuture fails with JDT but succeeds with javac
Product: [Eclipse Project] JDT Reporter: Simon Cheung <cheung.sai.ho>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: NEW --- QA Contact: Sasikanth Bharadwaj <sasikanth.bharadwaj>
Severity: normal    
Priority: P3 CC: cheung.sai.ho, jarthana, manoj.palat, mat.gessel+eclipse
Version: 4.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description Simon Cheung CLA 2016-09-09 06:04:06 EDT
The following sample code compiles using javac 1.8.0_45 but results in "Type mismatch" in Eclipse Neon 4.6 (org.eclipse.jdt.core_3.12.0.v20160516-2131.jar).

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

public class EclipseBug
{
    public static void main(String[] args)
    {
        // Fails with "Type mismatch: cannot convert from CompletableFuture<Object> to CompletableFuture<Map<String,String>>"
        CompletableFuture<Map<String, String>> future =
            someMethod().thenApply(map -> map.entrySet()
                                             .stream()
                                             .collect(Collectors.toMap(e -> transformKey(e.getKey()),
                                                                       e -> e.getValue())));
    }

    public static CompletableFuture<Map<Integer, String>> someMethod()
    {
        // Implementation not important
        return CompletableFuture.supplyAsync(HashMap::new);
    }

    public static String transformKey(Integer value)
    {
        // Implementation not important
        return value + "suffix";
    }
}
Comment 1 Jay Arthanareeswaran CLA 2016-09-09 06:11:51 EDT
I see this compiles fine as of latest I build. I will dig out which bug addressed this.
Comment 2 Mat Gessel CLA 2019-10-31 22:22:21 EDT
Works for me in JDT 3.18.100.v20190916-1045 ; tried ecj 1.8, 12.

Mark fixed?
Comment 3 Eclipse Genie CLA 2021-10-22 18:38:27 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2023-10-13 16:05:26 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.