typetools / typetools/checker-framework

Making two types have the same qualifier

Open
#1,326 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

Collection.remove throws a NullPointerException if its argument is null and the collection does not support null elements. Thus, remove should take a nullable parameter for a Collection containing nullable elements, and remove should take a non-null parameter for a Collection containing non-null elements.

Here is the desired effect:

  Collection<@Nullable String> cNullable;
  cNullable.remove(null);  // OK
  Collection<@NonNull String> cNonnull;
  cNonnull.remove(null);  // compile-time error

A way to annotate this would be:

interface Collection<E> {
  boolean remove(@NullnessOf(E) Object o) { ... }
}

Thus, the Nullness Checker needs to support an annotation such as @NullnessOf.
(Unless there is some other way to achieve the same effect.)

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 Nullness Checker and investigate how it could express a qualifier derived from a collection's element type. Compare the proposed @NullnessOf behavior with the two Collection examples; done means nullable collections accept null in remove while non-null collections reject it at compile time.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.