From 8d466ba21e53966dea091d0a57d0b727add890fc Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 06:11:18 +0000 Subject: [PATCH 01/10] docs: describe how to annotate existing API for nullability Fixes #26792 --- CONVENTIONS.md | 24 ++++++++++++++++++++++++ guidelines/design.md | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 9c1f1665318..10695400967 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -161,6 +161,30 @@ Put `@Nullable` on the declared type (`ValueSignal<@Nullable X>`). NullAway infers it for the constructor, so no repeated type argument or type witness is needed. +When annotating the first class of a package, add a `package-info.java` with +`@NullMarked` instead of annotating classes one by one. + +Adding `@Nullable` to a parameter or return type of an existing public method +is a source break for Kotlin callers, which treat JSpecify annotations as +strict. List it as a breaking change in the pull request and the release notes. +See `guidelines/design.md`. + +Do not introduce a wildcard such as `? extends @Nullable T` into a parameter +type of an existing overridable method: overrides with the old signature stop +compiling. Annotate the type argument instead (`Function`). + +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 +`@NullUnmarked` on a method, which turns off checking for all of its parameters +and its return type. If `@NullUnmarked` is unavoidable, link one tracking issue +instead of repeating the explanation on every method. + +Give the same parameter the same nullness across sibling methods: all +`executeJs`-style varargs methods either accept a `null` array or reject it. + ## `toString()` Keep `toString()` for people — logs, debugger views, exception messages — and diff --git a/guidelines/design.md b/guidelines/design.md index e3ac5f08520..218a667f900 100644 --- a/guidelines/design.md +++ b/guidelines/design.md @@ -173,6 +173,47 @@ public sealed interface Foo permits FooA, FooB, FooC {} and NullAway infers it for the constructor, so `new ValueSignal<>(null)` and `Signal.cached(...)` need no repeated type argument or type witness. +#### Annotating existing API + +The rules above are written for new code. Retrofitting JSpecify annotations +onto a class that already ships has traps of its own, and the fix for one of +them tends to break something else. The rules are in `CONVENTIONS.md`; this is +the reasoning behind them. + +- **It is a Kotlin source break.** Kotlin reads JSpecify annotations as strict + (the default since Kotlin 2.1), so marking an existing getter such as + `Element.getParent()` `@Nullable` makes `el.parent.tag` a compile error. + Removing the annotation later breaks the callers that adapted, in the other + direction. Java callers are unaffected unless they run NullAway, which is why + the change looks safe from the Java side. Treat it as a breaking change in a + minor release: say so in the pull request risks and the release notes. +- **Wildcards clash with overrides.** Changing a parameter of a non-final + method from `SerializableFunction` to + `SerializableFunction` keeps the + erasure but changes the signature, so an existing override with the old + parameter type fails with "name clash: … have the same erasure, yet neither + overrides the other". `SerializableFunction` + says the same thing without the clash. If even that does not fit, keep the + signature and document in the Javadoc that `null` is allowed. +- **Overloads keep their delegation.** If `getProperty(String)` delegates to + `getProperty(String, String)`, a subclass may override either one and rely + on the other going through it. Splitting the two to give them different + nullness changes which override takes effect. Check how callers actually use + an overload before tightening it, too: `getProperty(name, null)` is a common + idiom, so a non-null `defaultValue` contract would not hold. +- **`@NullUnmarked` is coarse.** On a method it turns off checking for every + parameter and the return type, not just the one generic argument that could + not be expressed. Annotating the type argument (`Signal<@Nullable String>`) + keeps the rest checked. When `@NullUnmarked` is the only way out, point to a + single tracking issue so the reason is written down once. +- **Siblings agree.** Methods that take the same parameter — `executeJs`, + `callJsFunction` and `addJsInitializer` all take a varargs array of + arguments — give it the same nullness. A caller should not find that `null` + is accepted by one and throws a `NullPointerException` in another. +- **The package needs a home for `@NullMarked`.** Some packages have no + `package-info.java` yet; add one with `@NullMarked` when annotating the + first class there, rather than marking classes individually. + ### Lifecycle and cleanup Resources that outlive a single request — watches, DOM listeners, timers, From 75617060ed341442e62b31d1c1ad01dd0c8e99ca Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Mon, 2 Nov 2026 06:16:29 +0000 Subject: [PATCH 02/10] docs: refine nullability rules for existing API --- CONVENTIONS.md | 17 ++++++++++------- guidelines/design.md | 31 +++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 10695400967..2d3a3f010d8 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -161,18 +161,21 @@ Put `@Nullable` on the declared type (`ValueSignal<@Nullable X>`). NullAway infers it for the constructor, so no repeated type argument or type witness is needed. -When annotating the first class of a package, add a `package-info.java` with -`@NullMarked` instead of annotating classes one by one. +When annotating existing classes, put `@NullMarked` on each class you have +audited. Add it at the package level (in `package-info.java`) only once every +class in the package has been audited, because it opts the whole package in. -Adding `@Nullable` to a parameter or return type of an existing public method -is a source break for Kotlin callers, which treat JSpecify annotations as -strict. List it as a breaking change in the pull request and the release notes. -See `guidelines/design.md`. +Marking an existing public API as null-marked or `@Nullable` can break Kotlin +code, which treats JSpecify annotations as strict: a `@Nullable` return type +breaks callers, and a `@Nullable` parameter of an overridable method breaks +Kotlin overrides that declare it non-null. List such a change as breaking in +the pull request and the release notes. See `guidelines/design.md`. Do not introduce a wildcard such as `? extends @Nullable T` into a parameter type of an existing overridable method: overrides with the old signature stop compiling. Annotate the type argument instead (`Function`). +Registration>`), noting that it no longer accepts a variable declared as +`Function`. Keep the existing delegation between overloads when annotating them. Do not split overloads to give them different nullness. diff --git a/guidelines/design.md b/guidelines/design.md index 218a667f900..5851dfb547b 100644 --- a/guidelines/design.md +++ b/guidelines/design.md @@ -180,20 +180,26 @@ onto a class that already ships has traps of its own, and the fix for one of them tends to break something else. The rules are in `CONVENTIONS.md`; this is the reasoning behind them. -- **It is a Kotlin source break.** Kotlin reads JSpecify annotations as strict - (the default since Kotlin 2.1), so marking an existing getter such as +- **It can be a Kotlin source break.** Kotlin reads JSpecify annotations as + strict (the default since Kotlin 2.1), so marking an existing getter such as `Element.getParent()` `@Nullable` makes `el.parent.tag` a compile error. - Removing the annotation later breaks the callers that adapted, in the other - direction. Java callers are unaffected unless they run NullAway, which is why - the change looks safe from the Java side. Treat it as a breaking change in a - minor release: say so in the pull request risks and the release notes. + 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 + type in it, which become non-null for Kotlin. Java callers are unaffected + unless they run NullAway, which is why the change looks safe from the Java + side. Treat it as a breaking change in a minor release: say so in the pull + request risks and the release notes. - **Wildcards clash with overrides.** Changing a parameter of a non-final method from `SerializableFunction` to `SerializableFunction` keeps the erasure but changes the signature, so an existing override with the old parameter type fails with "name clash: … have the same erasure, yet neither overrides the other". `SerializableFunction` - says the same thing without the clash. If even that does not fit, keep the + avoids the clash and accepts lambdas, the usual argument, unchanged. It is + not equivalent, though: type arguments are invariant, so a caller passing a + variable declared as `SerializableFunction` gets a type + mismatch in Kotlin and under NullAway. If neither form fits, keep the signature and document in the Javadoc that `null` is allowed. - **Overloads keep their delegation.** If `getProperty(String)` delegates to `getProperty(String, String)`, a subclass may override either one and rely @@ -210,9 +216,14 @@ the reasoning behind them. `callJsFunction` and `addJsInitializer` all take a varargs array of arguments — give it the same nullness. A caller should not find that `null` is accepted by one and throws a `NullPointerException` in another. -- **The package needs a home for `@NullMarked`.** Some packages have no - `package-info.java` yet; add one with `@NullMarked` when annotating the - first class there, rather than marking classes individually. +- **Package-level `@NullMarked` covers every class.** With NullAway's + `OnlyNullMarked`, `@NullMarked` in `package-info.java` makes every class in + the package checked, and for Kotlin every unannotated type in it becomes + non-null without anyone having audited it. While a package is annotated + class by class (as the `Table*` and media classes in + `com.vaadin.flow.component.html` are), mark each audited class with + `@NullMarked`, and move the annotation to the package — adding a + `package-info.java` if there is none — once all of them are done. ### Lifecycle and cleanup From 1dec795f6bdff1da365cb2fb5ecfedcb53d12ad5 Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:19:05 +0000 Subject: [PATCH 03/10] docs: fix @NullUnmarked guidance and chapter pointers for nullability 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. --- CONVENTIONS.md | 30 +++++++++++++----------- guidelines/design.md | 56 +++++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 7d05969b97b..b80f3f0c285 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -164,29 +164,31 @@ needed. When annotating existing classes, put `@NullMarked` on each class you have audited. Add it at the package level (in `package-info.java`) only once every class in the package has been audited, because it opts the whole package in. +See `guidelines/design.md`. -Marking an existing public API as null-marked or `@Nullable` can break Kotlin -code, which treats JSpecify annotations as strict: a `@Nullable` return type -breaks callers, and a `@Nullable` parameter of an overridable method breaks -Kotlin overrides that declare it non-null. List such a change as breaking in -the pull request and the release notes. See `guidelines/design.md`. +Adding `@Nullable` or `@NullMarked` to existing public API can break Kotlin +code, which treats JSpecify annotations as strict. List such a change as +breaking in the pull request and the release notes. See +`guidelines/design.md`. Do not introduce a wildcard such as `? extends @Nullable T` into a parameter type of an existing overridable method: overrides with the old signature stop -compiling. Annotate the type argument instead (`Function`), noting that it no longer accepts a variable declared as -`Function`. +compiling. See `guidelines/design.md`. 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 -`@NullUnmarked` on a method, which turns off checking for all of its parameters -and its return type. If `@NullUnmarked` is unavoidable, link one tracking issue -instead of repeating the explanation on every method. +split overloads to give them different nullness. See `guidelines/design.md`. + +When a generic parameter of an existing method needs a nullable type argument, +annotate the type argument (`SerializableFunction`) if callers usually pass a lambda. If they pass a variable of +the unannotated type, or overrides declare it, as with `Signal` in +`Element.bindText`, use `@NullUnmarked` on the method and link one tracking +issue instead of repeating the explanation on every method. See +`guidelines/design.md`. Give the same parameter the same nullness across sibling methods: all `executeJs`-style varargs methods either accept a `null` array or reject it. +See `guidelines/design.md`. ## `toString()` diff --git a/guidelines/design.md b/guidelines/design.md index c9f3eb8d0a3..779824368e2 100644 --- a/guidelines/design.md +++ b/guidelines/design.md @@ -158,53 +158,55 @@ The reasoning behind the rules in the Nullability section of The rules above are written for new code. Retrofitting JSpecify annotations onto a class that already ships has traps of its own, and the fix for one of -them tends to break something else. The rules are in `CONVENTIONS.md`; this is -the reasoning behind them. +them tends to break something else. The points below explain the rules on +annotating existing classes in the Nullability section of +[`CONVENTIONS.md`](../CONVENTIONS.md#nullability): - **It can be a Kotlin source break.** Kotlin reads JSpecify annotations as strict (the default since Kotlin 2.1), so marking an existing getter such as `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 - type in it, which become non-null for Kotlin. Java callers are unaffected - unless they run NullAway, which is why the change looks safe from the Java - side. Treat it as a breaking change in a minor release: say so in the pull - request risks and the release notes. + compiling. Null-marking a class breaks the other way round, because every + unannotated type in it becomes non-null for Kotlin: a Kotlin caller passing + `null` to such a parameter stops compiling, and so does a Kotlin override + that declares the parameter nullable. Return types only get stricter, which + callers do not notice. Java callers are unaffected unless they run NullAway, + which is why the change looks safe from the Java side. - **Wildcards clash with overrides.** Changing a parameter of a non-final method from `SerializableFunction` to `SerializableFunction` keeps the erasure but changes the signature, so an existing override with the old parameter type fails with "name clash: … have the same erasure, yet neither - overrides the other". `SerializableFunction` - avoids the clash and accepts lambdas, the usual argument, unchanged. It is - not equivalent, though: type arguments are invariant, so a caller passing a - variable declared as `SerializableFunction` gets a type - mismatch in Kotlin and under NullAway. If neither form fits, keep the - signature and document in the Javadoc that `null` is allowed. + overrides the other". +- **An annotated type argument is not equivalent.** + `SerializableFunction` avoids the clash and + accepts lambdas, the usual argument, unchanged. Type arguments are + invariant, though, so a variable declared as + `SerializableFunction` no longer fits in Kotlin or under + NullAway, and an override declaring the old type argument no longer + matches. That rules it out where the argument is usually such a variable: + `Element.bindText(Signal)` is called with signals declared + elsewhere and can be overridden, and `Signal<@Nullable String>` would also + change the returned binding type. `@NullUnmarked` is then the + remaining choice. It turns off checking for every parameter and the return + type of the method, not just the one type argument, so it stays limited to + the methods that need it, and one tracking issue records why. - **Overloads keep their delegation.** If `getProperty(String)` delegates to `getProperty(String, String)`, a subclass may override either one and rely on the other going through it. Splitting the two to give them different nullness changes which override takes effect. Check how callers actually use an overload before tightening it, too: `getProperty(name, null)` is a common idiom, so a non-null `defaultValue` contract would not hold. -- **`@NullUnmarked` is coarse.** On a method it turns off checking for every - parameter and the return type, not just the one generic argument that could - not be expressed. Annotating the type argument (`Signal<@Nullable String>`) - keeps the rest checked. When `@NullUnmarked` is the only way out, point to a - single tracking issue so the reason is written down once. -- **Siblings agree.** Methods that take the same parameter — `executeJs`, - `callJsFunction` and `addJsInitializer` all take a varargs array of - arguments — give it the same nullness. A caller should not find that `null` - is accepted by one and throws a `NullPointerException` in another. +- **Siblings agree.** `executeJs`, `callJsFunction` and `addJsInitializer` all + take a varargs array of arguments. A caller should not find that `null` is + accepted by one and throws a `NullPointerException` in another. - **Package-level `@NullMarked` covers every class.** With NullAway's `OnlyNullMarked`, `@NullMarked` in `package-info.java` makes every class in the package checked, and for Kotlin every unannotated type in it becomes - non-null without anyone having audited it. While a package is annotated - class by class (as the `Table*` and media classes in - `com.vaadin.flow.component.html` are), mark each audited class with - `@NullMarked`, and move the annotation to the package — adding a - `package-info.java` if there is none — once all of them are done. + non-null without anyone having audited it. Marking class by class, as the + `Table*` and media classes in `com.vaadin.flow.component.html` are, keeps + that to the classes that have been reviewed. ### Lifecycle and cleanup From 76f2892c6c4e758526bec9099677a7cafe12f8be Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:19:47 +0000 Subject: [PATCH 04/10] docs: name the Kotlin return-type override break from null-marking --- guidelines/design.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/guidelines/design.md b/guidelines/design.md index 779824368e2..383b4c7c557 100644 --- a/guidelines/design.md +++ b/guidelines/design.md @@ -170,8 +170,9 @@ annotating existing classes in the Nullability section of compiling. Null-marking a class breaks the other way round, because every unannotated type in it becomes non-null for Kotlin: a Kotlin caller passing `null` to such a parameter stops compiling, and so does a Kotlin override - that declares the parameter nullable. Return types only get stricter, which - callers do not notice. Java callers are unaffected unless they run NullAway, + that declares the parameter nullable. Return types only get stricter: + callers do not notice, but a Kotlin override declaring a nullable return + type stops compiling. Java callers are unaffected unless they run NullAway, which is why the change looks safe from the Java side. - **Wildcards clash with overrides.** Changing a parameter of a non-final method from `SerializableFunction` to From c440946e9e50ee4014f7c62be2db218426c97a72 Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:33:24 +0000 Subject: [PATCH 05/10] docs: ask for a per-method comment on @NullUnmarked, as Element does No tracking issue exists for the Element @NullUnmarked methods; each carries its own comment, so describe that practice instead. --- CONVENTIONS.md | 4 ++-- guidelines/design.md | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index b80f3f0c285..59edd5f8f49 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -182,8 +182,8 @@ When a generic parameter of an existing method needs a nullable type argument, annotate the type argument (`SerializableFunction`) if callers usually pass a lambda. If they pass a variable of the unannotated type, or overrides declare it, as with `Signal` in -`Element.bindText`, use `@NullUnmarked` on the method and link one tracking -issue instead of repeating the explanation on every method. See +`Element.bindText`, use `@NullUnmarked` on the method, with a short comment +saying which value may be null and why the type argument is not annotated. See `guidelines/design.md`. Give the same parameter the same nullness across sibling methods: all diff --git a/guidelines/design.md b/guidelines/design.md index 383b4c7c557..258db57ffb1 100644 --- a/guidelines/design.md +++ b/guidelines/design.md @@ -192,7 +192,8 @@ annotating existing classes in the Nullability section of change the returned binding type. `@NullUnmarked` is then the remaining choice. It turns off checking for every parameter and the return type of the method, not just the one type argument, so it stays limited to - the methods that need it, and one tracking issue records why. + the methods that need it, and a comment on each says why, so the next + person does not "fix" it by annotating the type argument. - **Overloads keep their delegation.** If `getProperty(String)` delegates to `getProperty(String, String)`, a subclass may override either one and rely on the other going through it. Splitting the two to give them different From b3eec3969b8328eab96922e1023aa7e6aedbf0e5 Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:46:15 +0000 Subject: [PATCH 06/10] docs: point the Kotlin-break rule at the repo's breaking-change markers --- CONVENTIONS.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 59edd5f8f49..a233ee541fc 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -167,8 +167,10 @@ 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 -code, which treats JSpecify annotations as strict. List such a change as -breaking in the pull request and the release notes. See +code, which treats JSpecify annotations as strict. Mark such a change as +breaking even though Java callers compile unchanged: a `!` in the commit and +pull request title and a `> [!WARNING]` block in the description, as the +skill linked from the Commit & PR Hygiene section describes. See `guidelines/design.md`. Do not introduce a wildcard such as `? extends @Nullable T` into a parameter From dcc1bd2ba0dd473013451b621c292bf6ca00548a Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:46:46 +0000 Subject: [PATCH 07/10] docs: limit the Java-compatibility claim to callers without NullAway --- CONVENTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index a233ee541fc..9a389c044ee 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -168,7 +168,7 @@ See `guidelines/design.md`. 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 compile unchanged: a `!` in the commit and +breaking even though Java callers without NullAway compile unchanged: a `!` in the commit and pull request title and a `> [!WARNING]` block in the description, as the skill linked from the Commit & PR Hygiene section describes. See `guidelines/design.md`. From 4eb277fe5d1aec2993f79fee4e4d63089f52d776 Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:59:19 +0000 Subject: [PATCH 08/10] docs: drop overrides as a reason for @NullUnmarked 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. --- CONVENTIONS.md | 5 +++-- guidelines/design.md | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 9a389c044ee..903aec216f9 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -182,8 +182,9 @@ split overloads to give them different nullness. See `guidelines/design.md`. When a generic parameter of an existing method needs a nullable type argument, annotate the type argument (`SerializableFunction`) if callers usually pass a lambda. If they pass a variable of -the unannotated type, or overrides declare it, as with `Signal` in +Registration>`) if callers usually pass a lambda. If they usually pass a +variable of the unannotated type, or the annotation would change another part +of the signature, as with `Signal` and the returned binding type in `Element.bindText`, use `@NullUnmarked` on the method, with a short comment saying which value may be null and why the type argument is not annotated. See `guidelines/design.md`. diff --git a/guidelines/design.md b/guidelines/design.md index 258db57ffb1..ca92a243018 100644 --- a/guidelines/design.md +++ b/guidelines/design.md @@ -185,12 +185,14 @@ annotating existing classes in the Nullability section of accepts lambdas, the usual argument, unchanged. Type arguments are invariant, though, so a variable declared as `SerializableFunction` no longer fits in Kotlin or under - NullAway, and an override declaring the old type argument no longer - matches. That rules it out where the argument is usually such a variable: + NullAway. Overrides are less affected: a Java override that keeps the old + type argument still compiles and is called, as it does for + `Component.whenAttached`; only a Kotlin or null-marked Java override gets a + nullness mismatch. That rules the annotation out where the argument is + usually such a variable, or where it would change more than the parameter: `Element.bindText(Signal)` is called with signals declared - elsewhere and can be overridden, and `Signal<@Nullable String>` would also - change the returned binding type. `@NullUnmarked` is then the - remaining choice. It turns off checking for every parameter and the return + elsewhere, and `Signal<@Nullable String>` would also change the returned + binding type. `@NullUnmarked` is then the remaining choice. It turns off checking for every parameter and the return type of the method, not just the one type argument, so it stays limited to the methods that need it, and a comment on each says why, so the next person does not "fix" it by annotating the type argument. From dc6b259ce7b79264bdb251fa28c4a71f9d3628c5 Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:59:54 +0000 Subject: [PATCH 09/10] docs: rewrap edited nullability paragraphs --- CONVENTIONS.md | 8 ++++---- guidelines/design.md | 25 ++++++++++++------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index 903aec216f9..e3df81897cb 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -168,10 +168,10 @@ See `guidelines/design.md`. 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 description, as the -skill linked from the Commit & PR Hygiene section describes. See -`guidelines/design.md`. +breaking even though Java callers without NullAway compile unchanged: a `!` in +the commit and pull request title and a `> [!WARNING]` block in the +description, as the skill linked from the Commit & PR Hygiene section +describes. See `guidelines/design.md`. Do not introduce a wildcard such as `? extends @Nullable T` into a parameter type of an existing overridable method: overrides with the old signature stop diff --git a/guidelines/design.md b/guidelines/design.md index ca92a243018..6224fd95df9 100644 --- a/guidelines/design.md +++ b/guidelines/design.md @@ -182,20 +182,19 @@ annotating existing classes in the Nullability section of overrides the other". - **An annotated type argument is not equivalent.** `SerializableFunction` avoids the clash and - accepts lambdas, the usual argument, unchanged. Type arguments are - invariant, though, so a variable declared as - `SerializableFunction` no longer fits in Kotlin or under - NullAway. Overrides are less affected: a Java override that keeps the old - type argument still compiles and is called, as it does for + accepts lambdas, the usual argument, unchanged. Type arguments are invariant, though, so a variable + declared as `SerializableFunction` no longer fits in Kotlin + or under NullAway. Overrides are less affected: a Java override that keeps the + old type argument still compiles and is called, as it does for `Component.whenAttached`; only a Kotlin or null-marked Java override gets a - nullness mismatch. That rules the annotation out where the argument is - usually such a variable, or where it would change more than the parameter: - `Element.bindText(Signal)` is called with signals declared - elsewhere, and `Signal<@Nullable String>` would also change the returned - binding type. `@NullUnmarked` is then the remaining choice. It turns off checking for every parameter and the return - type of the method, not just the one type argument, so it stays limited to - the methods that need it, and a comment on each says why, so the next - person does not "fix" it by annotating the type argument. + nullness mismatch. That rules the annotation out where the argument is usually + such a variable, or where it would change more than the parameter: + `Element.bindText(Signal)` is called with signals declared elsewhere, + and `Signal<@Nullable String>` would also change the returned binding type. + `@NullUnmarked` is then the remaining choice. It turns off checking for every + parameter and the return type of the method, not just the one type argument, + so it stays limited to the methods that need it, and a comment on each says + why, so the next person does not "fix" it by annotating the type argument. - **Overloads keep their delegation.** If `getProperty(String)` delegates to `getProperty(String, String)`, a subclass may override either one and rely on the other going through it. Splitting the two to give them different From 0b0358c214d1db957dd21cba180eb06cb65f7aad Mon Sep 17 00:00:00 2001 From: "totally-not-ai[bot]" <290682512+totally-not-ai[bot]@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:12:17 +0000 Subject: [PATCH 10/10] docs: scope package-level @NullMarked to new packages, use the Risks 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. --- CONVENTIONS.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index e3df81897cb..126b79eb654 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -140,8 +140,9 @@ then say what is different about it. See `guidelines/design.md`. ## Nullability -Apply `@NullMarked` (JSpecify) at the package level and annotate only what -genuinely may be null with `@Nullable`. +Apply `@NullMarked` (JSpecify) at the package level for a new package, and +on the class for a new class in a package that is not null-marked yet. +Annotate only what genuinely may be null with `@Nullable`. Return an empty collection, array, map or stream — never `null` — when there are no values. @@ -169,8 +170,8 @@ See `guidelines/design.md`. 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 -description, as the skill linked from the Commit & PR Hygiene section +the commit and pull request title and a ⚠️ Breaking change entry in the +description's risks, as the skill linked from the Commit & PR Hygiene section describes. See `guidelines/design.md`. Do not introduce a wildcard such as `? extends @Nullable T` into a parameter