Skip to content

[java] Type inference issue with unknown method ref in call chain #5329

@oowekyala

Description

@oowekyala

This surfaced as an FP of UnusedPrivateMethod. It is caused by the fact that collect is inferred to Map<Object, List<Item>> and not Map<(*unknown*), List<Item>>.


One of the examples where buildItem(a, b) method is considered as unused:

        List<SummaryDto.ItemDto> items = new ArrayList<>();
        loads.stream()
                .collect(Collectors.groupingBy(Item::getValue))
                .forEach((a, b) -> items.add(buildItem(a, b)));

        private SummaryDto.ItemDto buildItem(BigDecimal a, List<Item> b) {
            return SummaryDto.ItemDto.builder()....build();
        }

In the case of creating the same method without params - there is no issue

        List<SummaryDto.ItemDto> items = new ArrayList<>();
        loads.stream()
                .collect(Collectors.groupingBy(Item::getValue))
                .forEach((a, b) -> items.add(buildItem()));

        private SummaryDto.ItemDto buildItem() {
            return SummaryDto.ItemDto.builder()....build();
        }

Originally posted by @VitaliiIevtushenko in #5184 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions