typetools / typetools/checker-framework

Field with @RequiresNonNull + @MonotonicNonNull is treated as nullable inside lambda

Open
#6,595 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;

class Require {
  @MonotonicNonNull String s;

  @RequiresNonNull("s")
  Supplier<String> s() {
    return () -> s;
  }

  interface Supplier<T> {
    T get();
  }
}

Actual:

$ ./checker-framework-3.43.0/checker/bin/javac -processor nullness Require.java
Require.java:9: error: [return] incompatible types in return.
    return () -> s;
                 ^
  type of expression: @Initialized @MonotonicNonNull String
  method return type: @Initialized @NonNull String
1 error

Expected:

No error: Even though the lambda may run later, s is not only known to be non-null initially but is also known to remain so because of @MonotonicNonNull.

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 Require.java reproducer and run it through the nullness processor using the command shown in the issue. Trace how @RequiresNonNull and @MonotonicNonNull information is handled across the lambda; done means the example compiles without the reported return-type error and has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.