typetools / typetools/checker-framework

@NotOnlyInitialized ignored in inline initialization scenarios

Open
#813 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

@NotOnlyInitialized seems to fall short in cases of inline initialization.

import org.checkerframework.checker.initialization.qual.NotOnlyInitialized;
import org.checkerframework.checker.initialization.qual.UnderInitialization;

class A {
  static interface I {}

  static class B {
    B(@UnderInitialization I stuff) { }
  }

  static class Fails implements I {
    @NotOnlyInitialized B bar = new B(this);
    // a.java:15: error: [assignment.type.incompatible] incompatible types in assignment.
    //     @NotOnlyInitialized B bar = new B(this);
    //                                 ^
    //   found   : @UnderInitialization(A.B.class) @NonNull B
    //   required: @Initialized @NonNull B
  }
  static class works implements I {
    @NotOnlyInitialized B bar;
    {
      bar = new B(this); // works
    }
  }
}

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 Java reproducer in the issue and compare the inline field initializer with the equivalent initializer block. Trace how the initialization checker handles @NotOnlyInitialized assignments involving new B(this); done means the inline form receives the intended treatment without regressing the working form.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.