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

Consider restricting Stream.ofNullable to non-null type arguments #97

Open
cpovirk opened this issue Oct 4, 2024 · 0 comments
Open

Comments

@cpovirk
Copy link
Collaborator

cpovirk commented Oct 4, 2024

https://github.com/jspecify/jdk/blob/3669c24f878cf1dbaf42ccd75b002cdbc94fd4da/src/java.base/share/classes/java/util/stream/Stream.java#L1471C57-L1471C67

We could change the declaration of T to just <T>. That would be "simpler," and it could maybe in theory help someone who isn't realizing that the output is a Stream<@NonNull E> for some parametric-nullness type parameter E? But it might also annoy people who do actually want a Stream<SomeTypeThatMightIncludeNull>.

(TODO: Dig up past discussions of google/guava#1927 (comment) through the lens of nullness. The idea here would be that you can always map(t -> t) to change the type if you want to. [edit: Here we go: jspecify/jspecify#525. And I guess maybe this issue fits better in the jspecify/jspecify repo unless we do want to start using this repo's issues more?])

One thing to note is that the current signature works well for the Checker Framework for converting a Stream<@Nullable Foo> to a Stream<Foo> via flatMap(Stream::ofNullable). I imagine that the proposed signature would, too, but it would be good to check.

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

1 participant