typetools / typetools/checker-framework

Permit constructor invocation to return @Initialized, even if an argument is non-@Initialized

Open
#223 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently the Nullness Checker follows the Freedom-Before-Commitment rules
for constructor invocations:  If all the arguments to the constructor are
@Initialized, then the constructor result is @Initialized.  Otherwise the
new object, which is presumed to have stored arguments in its internal
state, might not have finished initialization, and is thus
@UnknownInitialization.

This behavior is unnecessarily restrictive.  If an @UnknownInitialization
formal parameter is stored only in an @UnknownInitialization field, then
the constructor result can safely be considered @Initialized.  (The
Freedom-Before-Commitment rules don't allow an @UnknownInitialization
field, but our implementation is more flexible and permits this use case).

The Nullness Checker should permit a formal parameter to be marked
indicating that it is only stored in an @UnknownInitialization field.
Possible names for the formal parameter annotation are:
  @NotEventuallyInitialized
  @NotPartOfInitializationState
  @OutsideInitializedState 
  @Uninitialized
  @UninitializedState
  @UninitializedField

The rules could be:
 * a parameter marked as @UninitializedField must obey all subtyping rules
   even within the constructor.
   (Currently, the Nullness Checker permits a constructor to perform
   type-unsafe assignments into fields:  an @UnknownInitialization or
   @UnderInitialization value may be stored into an @Initialized field even
   though this violates the type system.  That is safe under the more
   restrictive FBC rules that forbid @UnknownInitialization fields, but it
   is our goal to permit such fields.)
 * a parameter marked as @UninitializedField may only be stored in a field
   or passed to another @UninitializedField formal parameter.

This comes up in plume-lib's Options class, when making an OptionsInfo
object that has an @UnknownInitialization field.

Original issue reported on code.google.com by michael.ernst@gmail.com on 21 May 2013 at 4:27

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 Nullness Checker’s Freedom-Before-Commitment handling for constructor invocations and review how @UnknownInitialization fields and formal parameters are represented. Compare the proposed annotation names and storage rules with the Options class use case in plume-lib. Done means a chosen annotation and specified checking rules permit the safe constructor result while preserving subtyping constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.