Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream result after cast evaluated as having @PolyNull element #6739

Open
MichalStehlikCz opened this issue Aug 6, 2024 · 2 comments
Open
Assignees

Comments

@MichalStehlikCz
Copy link
Contributor

MichalStehlikCz commented Aug 6, 2024

Compilation of

public class Test {

  public <T> Collection<T> clear(Class<T> type) {
    return Stream.of("abc")
        .map(type::cast)
        .toList();
  }
}

fails with

java: [return] incompatible types in return.
  type of expression: @Initialized @NonNull List<T extends @Initialized @PolyNull Object>
  method return type: @Initialized @NonNull Collection<T extends @Initialized @Nullable Object>

function with @PolyNull annotated return type should evaluate based on its argument type (e.g. @NonNull in this case)

Worked fine in 3.42.0, broken in 3.46.0

@MichalStehlikCz
Copy link
Contributor Author

... works fine when lambda is used instead of method reference

public class Test {

  public <T> Collection<@NonNull T> clear(Class<T> type) {
    return Stream.of("abc")
        .map(value -> type.cast(value))
        .toList();
  }
}

@mernst
Copy link
Member

mernst commented Aug 6, 2024

@MichalStehlikCz Thanks for the bug reports; we appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants