Bug 501128 - Type inference with lambdas & CompletableFuture fails with JDT but succeeds with javac
Summary: Type inference with lambdas & CompletableFuture fails with JDT but succeeds w...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact: Sasikanth Bharadwaj CLA
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-09 06:04 EDT by Simon Cheung CLA
Modified: 2023-10-13 16:05 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 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.