jspecify / jspecify/jdk

Revisit nullness of Collectors.toMap

Open
#147 0 comments 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

It looks like we have the key types as nullable but the value type not? I would have guessed that they'd both be nullable.

I wonder if part of the story here is that the ones that declare a mergeFunction would want a non-null type argument there? But, if so:

  • We could accomplish that with @NonNull.
  • It's not clear to me that a nullable type argument there would be wrong, just potentially inconvenient in some cases (and convenient in others).

I'm belatedly realizing that a Guava user had raised a related question before in https://github.com/google/guava/issues/6824. So part of the story might be that a more flexible signature has been difficult for some tools in the past. But I know that the Checker Framework improved its type inference a while back, so we should get some real-world data on this once we're able to import those changes to Google's monorepo.

(I noticed this as I was putting together https://github.com/jspecify/jdk/pull/146.)

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 by comparing the three Collectors.toMap declarations in src/java.base/share/classes/java/util/stream/Collectors.java at the referenced lines. Review the related Guava issue and consider the Checker Framework inference context; done means reaching a justified decision on nullness for keys, values, and mergeFunction, supported by real-world tooling data.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.