typetools / typetools/checker-framework

NotOnlyInitialized prevents this from becoming UnderInitialization(current.class)

Open
#4,667 1 comment 0 reactions 1 assignee View on GitHub

@mernst is already working on this.

Since May 20, 2021.

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

Description

It seems that using @NotOnlyInitialized prevents a class from becoming @UnderInitialization(current.class) before the end of the constructor. This problem is what caused me to request #4613 .

ChooseChallengeDescriptor.java

package net.mtu.eggplant.checker.issue4613;

import org.checkerframework.checker.initialization.qual.UnknownInitialization;

import javax.swing.JDialog;
import java.awt.Frame;

public class ChooseChallengeDescriptor extends JDialog {

  public ChooseChallengeDescriptor(final @UnknownInitialization(Frame.class) Frame owner) {
    super(owner, true);
  }
}

The warning about owner not matching the parent class type is handled by a stub file in my project.

SchedulerUI.java

package net.mtu.eggplant.checker.issue4613;

import org.checkerframework.checker.initialization.qual.UnderInitialization;
import org.checkerframework.checker.initialization.qual.UnknownInitialization;
import org.checkerframework.checker.initialization.qual.NotOnlyInitialized;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;

import javax.swing.JFrame;
import javax.swing.JMenuBar;

public class SchedulerUI extends JFrame {

  private final @NotOnlyInitialized ChooseChallengeDescriptor chooseChallengeDescriptor;

  public SchedulerUI() {
    super("base title");

    chooseChallengeDescriptor = new ChooseChallengeDescriptor(SchedulerUI.this);

    // object initialized
    createMenubar();
  }

  private JMenuBar createMenubar(@UnknownInitialization(SchedulerUI.class) SchedulerUI this) {
    final JMenuBar menubar = new JMenuBar();

    return menubar;
  }
}

The warning that I am having issues with is

/home/jpschewe/projects/checker-bugs/src/main/java/net/mtu/eggplant/checker/issue4613/SchedulerUI.java:21: error: [method.invocation.invalid] call to createMenubar() not allowed on the given receiver.
    createMenubar();
                 ^
  found   : @UnderInitialization(javax.swing.JFrame.class) @NonNull SchedulerUI
  required: @UnknownInitialization(net.mtu.eggplant.checker.issue4613.SchedulerUI.class) @NonNull SchedulerUI

I would have expected this to be @UnderInitialization(SchedulerUI.class) at the point that createMenubar() is called.

This is using checker 3.13.0 and OpenJDK 11.

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.