Bug 567218 - overloaded static method reference infer failed
Summary: overloaded static method reference infer failed
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.16   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: regression
Depends on:
Blocks:
 
Reported: 2020-09-21 13:46 EDT by Sid Lv CLA
Modified: 2023-06-06 13:15 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 Sid Lv CLA 2020-09-21 13:46:39 EDT
class UserService {

    public static UserBrief findBrief(long userId) {
        ...
    }

    public static Map<Long, UserBrief> findBrief(Set<Long> userIds) {
	return userIds.stream().map(UserService::findBrief).filter(...);
    }
}


When move mouse at position of .map(), the hint is:
<Object> Stream<Object> java.util.stream.Stream.map(Function<? super Long, ? extends Object> mapper)

and then move to .filter() there will be no hint anymore. If change the code above to:
.map(id -> findBrief(id))
then the hint will be right.

This bug I found in Eclipse IDE for Java Developers Version: 2020-06 (4.16.0) and dosen't appear at Version201912.
Comment 1 Jeff Johnston CLA 2021-05-27 22:39:38 EDT
Fleshing out the example and moving to JDT Core after debugging on 4.20 M3:

When the last line has the method reference, line 845 of MessageSend.java (resolveType())

	if (!this.binding.isValidBinding()) {

notes that the binding is not valid as it is a ProblemMethodBinding with problem id 23.  This causes it to return back to: CompletionOnMemberAccess.resolveType() with null and this causes it to throw a CompletionNodeFound exception with no ASTNode and then the code at:

CompletionEngine: 2291 has no ASTNode and so does not call complete().

In the editor, the entire line up to the last . is highlighed in error.

When the last line below is changed to:

    return userIds.stream().map((id) -> findBrief(id)).

only the last . is marked in error and the line 845 of MessageSend.java passes as a valid binding so it resolves the type and CompletionEngine: 2291 will find an ASTNode in the CompletionNodeFound exception and calls complete() which finds the various Stream methods.

import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

class UserService {

    public static class UserBrief {
        private int a;
        
        public UserBrief(int a) {
            this.a = a;
        }
        
        public int getA() {
            return a;
        }
        
        public String toString() {
            return Integer.toString(a);
        }
    }
    public static UserBrief findBrief(long userId) {
        return new UserBrief((int)userId);
    }

    public static Map<Long, UserBrief> findBrief(Set<Long> userIds) {
    return userIds.stream().map(UserService::findBrief).
    }
}
Comment 2 Sarika Sinha CLA 2021-06-04 08:29:20 EDT
I see that now if I add ";" to return userIds.stream().map(UserService::findBrief)
and then I see "." gives the completion proposals.


Where as in 4.14 completion proposal was returned without that.

Also, just for curiosity -
What was the final method -
public static Map<Long, UserBrief> findBrief(Set<Long> userIds) {
	return userIds.stream().map(UserService::findBrief).filter(...);
    }

I mean what was the completion to convert Stream<UserBrief> to Map<Long, UserBrief> ?
Comment 3 Eclipse Genie CLA 2023-06-06 13:15:50 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.