Skip to content

Improve handling of wildcard upper bounds in generic method inference #1350

@msridhar

Description

@msridhar

Test case:

@Test
public void genericMethodLambdaArgWildCard() {
makeHelperWithInferenceFailureWarning()
.addSourceLines(
"Test.java",
"import org.jspecify.annotations.*;",
"import java.util.function.Function;",
"@NullMarked",
"class Test {",
" static <T, R> R invokeWithReturn(Function <? super T, ? extends @Nullable R> mapper) {",
" throw new RuntimeException();",
" }",
" static void test() {",
" // legal, should infer R -> Object but then the type of the lambda as ",
" // Function<Object, @Nullable Object> via wildcard upper bound",
" Object x = invokeWithReturn(t -> null);",
" }",
"}")
.doTest();
}

This reflects the suppression in Spring here. Since this comes up often, ideally we would find a way to get rid of this false positive without adding full support for wildcards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions