typetools / typetools/checker-framework

Constructor returns @UnderInitialization object with @UnderInitialization argument

Open
#5,788 0 comments 0 reactions 1 assignee View on GitHub

@mernst is already working on this.

Since May 3, 2023.

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

Description

Not sure if this is related to #409 but the setup is similar.

When a constructor for a class Bar takes a @UnderInitialization object as argument, it's return type somehow becomes @UnderInitialization(Bar.class) Bar. This sometimes cause false positive errors.

Command

checker/bin/javac -processor nullness Foo.java

Input

File Foo.java

final class Foo {
  private static class Bar {
    private Bar(@UnderInitialization Foo foo) {}
  }

  public Foo() {
    bar = new Bar(this);
  }

  private Bar bar;
}

Output

Foo.java:12: error: [assignment] incompatible types in assignment.
    bar = new Bar(this);
          ^
  found   : @UnderInitialization(com.google.Foo.Bar.class) @NonNull Bar
  required: @Initialized @NonNull Bar
1 error

Expectation

Return type of a constructor should always be @Initialized.

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.