typetools / typetools/checker-framework

@EnsuresNonNull[If] should ensure all fields on a path are non-null

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

@wmdietl is already working on this.

Since Mar 27, 2018.

False Positive (false warning or imprecision)
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

In the example below, method bar ensures that this.field.value is non-null.
However an error for the dereference of this.field is generated.
I looked at the Store and it only contains a value for this.field.value, not for this.field, which explains the error.
Probably similar problems exist for other flow expressions.

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

class Demo {
    class A {
        @Nullable Object value;
    }
    
    @Nullable A field;
    
    @EnsuresNonNull("this.field.value")
    void bar() {
        this.field = new A();
        this.field.value = "";
    }
    
  void foo() {
    bar();
    this.field.toString();
  }
}

I'm working on an improvement to the CFG & Store and noticed this issue when debugging an issue at
https://github.com/typetools/checker-framework/blob/master/checker/src/org/checkerframework/checker/initialization/InitializationVisitor.java#L183
I don't understand why that code doesn't fail on master, but this false positive illustrates the same issue with the Store.

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.