Support JEP 513: this(...) after a constructor prologue

Open Beginner friendly
#2,145 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Read NullAway.constructorInvokesAnother and trace how it checks constructor body statements, then inspect the related constructor analysis tests. Add a regression case with a statement before this(...); done means the example no longer reports an uninitialized @NonNull field, while existing constructor checks still pass.

Written by the indexing model from the issue text.

Description

JEP 513 (flexible constructor bodies) is final in Java 25. A constructor may now run statements before this(...). NullAway does not handle this case yet. It does not see the this(...) call, so it reports that the constructor does not initialize a @NonNull field.

import org.jspecify.annotations.NullMarked;

@NullMarked
class Example {
    private String name;

    Example(String name) {
        this.name = name;
    }

    Example(String first, String last) {
        String full = first + " " + last;
        this(full);
    }
}

Expected: no error. The second constructor calls this(full), and the first constructor initializes name.

Actual:

Example.java:[13,4] error: [NullAway] initializer method does not guarantee @NonNull field 'name' (line 7) is initialized along all control-flow paths (remember to check for exceptions or early returns).

There is no error when this(first + " " + last) is the first statement. There is also no error when the field is final.

NullAway.constructorInvokesAnother checks only the first statement of the body (statements.get(0)). With a prologue, the this(...) call is not the first statement. The code on master is the same.

Versions: NullAway 0.14.3, Error Prone 2.52.0, JDK 25.0.2. Options: OnlyNullMarked=true, JSpecifyMode=true.

Dominant language
Java
Stars
4.1k
Forks
379
Avg merge
1d 2h
Merged PRs (30d)
106

Getting set up

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.

More from uber/NullAway

All issues in uber/NullAway

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.