typetools / typetools/checker-framework

Lambda implementing override-equivalent methods doesn't have return type checked against both

Open
#2,723 0 comments 0 reactions 1 assignee View on GitHub

@wmdietl is already working on this.

Since Dec 16, 2019.

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

Description

import org.checkerframework.checker.nullness.qual.Nullable;

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

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

interface BothSuppliers<T> extends Supplier1<T>, Supplier2<@Nullable T> {}

class Foo {
  public static void main(String[] args) {
    BothSuppliers<String> s = () -> null;
    ((Supplier1<String>) s).get().length();
  }
}
$ checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker Foo.java && java Foo
Exception in thread "main" java.lang.NullPointerException
  at Foo.main(Foo.java:16)

The lambda's return type is being checked against Supplier1.get() but not Supplier2.get(): If I switch the location of the @Nullable from Supplier1<T>, Supplier2<@Nullable T> to Supplier1<@Nullable T>, Supplier2<T>, then the Checker Framework detects the problem. And if I switch from a lambda to a class, the Checker Framework also detects the problem.

Source file and -version -verbose -AprintAllQualifiers output attached.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.