typetools / typetools/checker-framework

Constructor should not assume static fields are initialized

Open
#556 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Before the constructor is invoked, static initializers and static blocks are executed. This suggests that the Initialization Checker can assume that static fields are initialized in the constructor.

However, if any user-defined code -- including callbacks such as executions of equals() and hashCode() -- appears in a static initializer or static block, then static fields cannot be assumed to be initialized within the constructor.

A minimal test case appears in checker-framework/checker/tests/initialization/fbc/Issue556a.java , and a longer test case with explanations appears in checker-framework/checker/tests/initialization/fbc/Issue556b.java .

Thanks to Ed Price for pointing out the issue and supplying an initial test case.

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 checker/tests/initialization/fbc/Issue556a.java and Issue556b.java, then run the relevant Initialization Checker tests to reproduce the reported behavior. Trace how constructor assumptions are handled when static initializers or blocks execute user-defined callbacks. Done means both cases are correctly checked without regressing existing initialization tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.