Repository navigation
docs: describe how to annotate existing API for nullability - #26793
totally-not-ai[bot] wants to merge 11 commits into
Conversation
|
Test Results 1 675 files 1 761 suites 2h 7m 34s ⏱️ Results for commit 7561706. |
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 3 comments.
| Finding | |
|---|---|
| 📝 | The @NullUnmarked rule recommends an alternative that the codebase already rejected for the very example it uses. |
| 📝 | The sentence on null-marking a class describes the opposite effect from the break it actually causes. |
| 📐 | Four of the five new rules omit the chapter pointer the conventions file requires. |
| Keep the existing delegation between overloads when annotating them. Do not | ||
| split overloads to give them different nullness. | ||
|
|
||
| Annotate the specific type argument (`Signal<@Nullable String>`) rather than |
There was a problem hiding this comment.
📝 The @NullUnmarked rule recommends an alternative that the codebase already rejected for the very example it uses.
Signal<@Nullable String> is given as the preferred fix over @NullUnmarked, but the five @NullUnmarked methods in Element (bindText, bindAttribute, bindVisible, bindEnabled, …) are exactly that case, and each carries a comment explaining why the type argument cannot be annotated there: it changes the returned binding type and breaks overrides.
Unlike the SerializableFunction case, the ordinary argument here is a signal variable, not a lambda, so by this PR's own invariance argument Signal<@Nullable String> stops accepting Signal<String>. Button.bindText(Signal<String>) in flow-components is a real override that would clash.
The rules now leave the Signal case with no permitted option: no wildcard, no type argument, and @NullUnmarked only "if unavoidable". Either pick an example where annotating the type argument actually works, or say plainly that a non-lambda parameter is the case where @NullUnmarked is unavoidable.
CONVENTIONS.md:183 · documentation
There was a problem hiding this comment.
Agreed, the rule left the Signal case with no option. It now says: annotate the type argument when callers usually pass a lambda (SerializableFunction<UI, @Nullable Registration>), and use @NullUnmarked with one tracking issue when they pass a variable of the unannotated type or overrides declare it, naming Element.bindText(Signal<String>) as that case. The chapter explains why the annotated type argument fails there: invariance, overrides, and the changed binding type.
| `Element.getParent()` `@Nullable` makes `el.parent.tag` a compile error. | ||
| Making a parameter `@Nullable` relaxes the contract for callers, but a Kotlin | ||
| subclass whose override still declares that parameter non-null stops | ||
| compiling. Null-marking a class has the same effects for every unannotated |
There was a problem hiding this comment.
📝 The sentence on null-marking a class describes the opposite effect from the break it actually causes.
Null-marking makes unannotated types non-null, so it does not produce "the same effects" as the two @Nullable cases just described. The breaks are the mirror image:
- Kotlin callers passing
nullinto a parameter that is now non-null stop compiling. - Kotlin overrides that declare such a parameter nullable clash.
Return types get strictly better (platform type becomes non-null), which is the one case the preceding sentence would lead a reader to expect to break. Since this bullet exists to tell a contributor what to look for when reviewing a null-marking PR, it should name the parameter break directly.
design.md:169 · documentation
There was a problem hiding this comment.
Right, null-marking breaks the other way round. The bullet now names those breaks: Kotlin callers passing null to a now non-null parameter, Kotlin overrides declaring such a parameter nullable, and Kotlin overrides declaring a nullable return type. Plain callers of return types are unaffected.
| infers it for the constructor, so no repeated type argument or type witness is | ||
| needed. | ||
|
|
||
| When annotating existing classes, put `@NullMarked` on each class you have |
There was a problem hiding this comment.
📐 Four of the five new rules omit the chapter pointer the conventions file requires.
The Conventions and Guidelines section says to "end it with "See guidelines/<chapter>.md." when the reasoning needs more room than a sentence". Each new rule has a full bullet of reasoning in design.md, yet only the Kotlin one carries the pointer.
The same section also says a chapter "links to the rule it explains instead of restating it"; the new bullets end by repeating their rule ("give it the same nullness", "point to a single tracking issue", "mark each audited class … once all of them are done").
CONVENTIONS.md:164 · conventions
There was a problem hiding this comment.
Every new rule now ends with "See guidelines/design.md." The chapter subsection links to the Nullability section of CONVENTIONS.md and gives only the reasoning; the bullets no longer repeat the rules. The Kotlin rule also dropped the details that now live only in the chapter.
… retrofit rules Allow @NullUnmarked where the generic argument is usually a variable rather than a lambda (as with Element.bindText), describe the Kotlin break null-marking causes correctly, and point every new rule to the chapter, which no longer restates the rules.
| annotate the type argument (`SerializableFunction<UI, @Nullable | ||
| Registration>`) if callers usually pass a lambda. If they pass a variable of | ||
| the unannotated type, or overrides declare it, as with `Signal<String>` in | ||
| `Element.bindText`, use `@NullUnmarked` on the method and link one tracking |
There was a problem hiding this comment.
📝 The @NullUnmarked rule asks for a tracking issue that does not exist, and the example it names does the opposite.
The rule says to "link one tracking issue instead of repeating the explanation on every method", and the chapter asserts "one tracking issue records why". In the code, the five @NullUnmarked methods in Element (bindText, bindAttribute, bindAttributeBoolean, bindVisible, bindEnabled) each carry their own comment and link nothing; no tracking issue is referenced anywhere in the repository.
So a contributor following the rule has no issue to link, and the named exemplar shows the practice the rule forbids. Either file the issue and point the existing comments at it, or write the rule as the per-method comment the code already uses.
CONVENTIONS.md:185 · documentation
There was a problem hiding this comment.
Good catch, there is no such issue. The rule now matches what Element already does: @NullUnmarked on the method, with a short comment there saying which value may be null and why the type argument is not annotated. The chapter says the comment is there so nobody later "fixes" the method by annotating the type argument.
No tracking issue exists for the Element @NullUnmarked methods; each carries its own comment, so describe that practice instead.
| class in the package has been audited, because it opts the whole package in. | ||
| See `guidelines/design.md`. | ||
|
|
||
| Adding `@Nullable` or `@NullMarked` to existing public API can break Kotlin |
There was a problem hiding this comment.
📐 The breaking-change rule asks for something the repo marks differently, and never names the ! marker.
How a breaking change is declared is already defined in the commit-and-pr skill that this file delegates PR shape to: a ! in the title and a > [!WARNING] block in the description. The new rule instead says to list such a change as breaking "in the pull request and the release notes", which names no mechanism this repo has — the release digest classifies commits by conventional-commit type, so a Kotlin break mentioned only in prose never reaches it.
Pointing the rule at the existing marker would make it actionable; the genuinely new information (a Kotlin-only source break counts as breaking) survives either way.
CONVENTIONS.md:169 · conventions
There was a problem hiding this comment.
Agreed. The rule now uses the repo's existing markers: a ! in the commit and PR title and a > [!WARNING] block in the description, pointing to the skill linked from Commit & PR Hygiene. It still says that a Kotlin-only source break counts as breaking, even though Java callers without NullAway compile unchanged. The "release notes" wording is gone.
| When a generic parameter of an existing method needs a nullable type argument, | ||
| annotate the type argument (`SerializableFunction<UI, @Nullable | ||
| Registration>`) if callers usually pass a lambda. If they pass a variable of | ||
| the unannotated type, or overrides declare it, as with `Signal<String>` in |
There was a problem hiding this comment.
📝 The "or overrides declare it" criterion sends the rule's own positive example to the opposite branch.
whenAttached is cited as the case for annotating the type argument, yet it is overridable and overrides declaring the old SerializableFunction<UI, Registration> are explicitly supported — ComponentTest.whenAttached_overrideWithOriginalParameterType_isCalled exists to prove the override still compiles and is invoked. Read literally, the criterion routes that method to @NullUnmarked, which is not what the code does.
The chapter's supporting sentence ("an override declaring the old type argument no longer matches") is unqualified and reads, after the preceding name-clash bullet, as a Java compile break. That holds for the wildcard form, not for the invariant one. What actually separates the two cases is whether the old-typed override lives in Kotlin or null-marked Java, plus the changed binding type for the signal bindings — worth saying directly, since Button.bindText in flow-components is not null-marked either.
CONVENTIONS.md:186 · documentation
There was a problem hiding this comment.
Right, overrides are not the deciding factor. The rule now chooses @NullUnmarked when callers usually pass a variable of the unannotated type, or when the annotation would change another part of the signature, such as the returned binding type in Element.bindText. The chapter now says that a Java override keeping the old type argument still compiles and is called, as with Component.whenAttached. Only a Kotlin or null-marked Java override gets a nullness mismatch.
A plain Java override keeping the old type argument still compiles, as Component.whenAttached shows; the signal bindings need @NullUnmarked because callers pass signal variables and the return type would change.
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 2 comments.
| Finding | |
|---|---|
| 📐 | The breaking-change rule attributes a > [!WARNING] block in the PR description to the commit-and-pr skill, which puts that block in the first comment. |
| 📝 | The new class-by-class @NullMarked rule contradicts the unqualified package-level rule a few paragraphs above it. |
| Adding `@Nullable` or `@NullMarked` to existing public API can break Kotlin | ||
| code, which treats JSpecify annotations as strict. Mark such a change as | ||
| breaking even though Java callers without NullAway compile unchanged: a `!` in | ||
| the commit and pull request title and a `> [!WARNING]` block in the |
There was a problem hiding this comment.
📐 The breaking-change rule attributes a > [!WARNING] block in the PR description to the commit-and-pr skill, which puts that block in the first comment.
In the skill, > [!WARNING] is listed under Optional extras of the first comment, after "How to test". The description has a fixed template that ends with the what-changed bullets ("Nothing below the bullets"), and its marker for a breaking change is the
Pointing the rule at ! in the title plus the
CONVENTIONS.md:172 · conventions
There was a problem hiding this comment.
Fixed. The rule now asks for a ! in the commit and PR title and a > [!WARNING] mention is gone.
| infers it for the constructor, so no repeated type argument or type witness is | ||
| needed. | ||
|
|
||
| When annotating existing classes, put `@NullMarked` on each class you have |
There was a problem hiding this comment.
📝 The new class-by-class @NullMarked rule contradicts the unqualified package-level rule a few paragraphs above it.
The section still opens with "Apply @NullMarked (JSpecify) at the package level", with no scope limiting it to new code. For the common case of a new class in an existing, unaudited package the two rules point opposite ways, and the file that "decides" offers no resolution — the scoping ("the rules above are written for new code") exists only in the chapter, which by this file's own division cannot carry rules.
Scoping the first rule in CONVENTIONS.md itself would settle it.
CONVENTIONS.md:164 · documentation
There was a problem hiding this comment.
Agreed, CONVENTIONS.md should settle this itself. The opening rule now applies package-level @NullMarked only to a new package. A new class in a package that is not null-marked yet gets @NullMarked on the class. That matches the class-by-class rule for existing packages.
…breaking flag The opening Nullability rule now says where @NullMarked goes for a new class in a package that is not null-marked yet, so it no longer contradicts the class-by-class rule. The Kotlin-break rule points at the breaking-change entry in the description's risks, which is where the commit-and-pr skill puts it.



Review risk: two-way door — docs only, affects contributor guidance
Fixes #26792
DX/docs · contributor guidelines · anyone adding JSpecify annotations to existing public API
The nullability guidance only covered new code. Adding
@NullMarked/@Nullableto a class that already ships has compatibility traps (Kotlin source breaks, override clashes from wildcards, overload delegation, coarse@NullUnmarked) that are not obvious from the existing rules. This adds rules and the reasoning behind them.Risks:
✅ Docs only, no code changes
CONVENTIONS.md(Nullability): the package-level@NullMarkedrule is scoped to new packages (a new class in a package that is not null-marked yet gets it on the class); new rules, each pointing to the chapter — mark audited classes@NullMarkedand move to package level only once the whole package is audited; mark@Nullableor@NullMarkedon existing API as breaking (!in the title,@NullUnmarked(with a comment saying why) when they usually pass a variable of the unannotated type, or the annotation would change another part of the signature (such as the returned binding type inElement.bindText); consistent nullness for the same parameter across sibling methods.guidelines/design.md: new "Annotating existing API" subsection under "Nullability discipline" explaining each rule with the concrete failure it prevents, including what breaks for Kotlin:@Nullablereturns break callers,@Nullableparameters break overrides, and null-marking breaks callers passingnulland overrides declaring a nullable parameter or return type.