jspecify / jspecify/jdk

Consider restricting `Stream.ofNullable` to non-null type arguments

Open
#97 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
7
Forks
3
Avg merge
15h 17m
Merged PRs (30d)
8

Description

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 https://github.com/google/guava/issues/1927#issuecomment-68305122 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Stream.ofNullable declaration in src/java.base/share/classes/java/util/stream/Stream.java at the linked line. Review the linked Guava and JSpecify discussions, then check whether the proposed signature preserves the Checker Framework conversion described in the issue. Done means reaching a justified decision about the signature and documenting the nullness and compatibility implications.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.