Repository navigation
In review
Copy link
Labels
Description
Problem
guidelines/design.md ("Nullability discipline") and CONVENTIONS.md describe how to annotate new code with JSpecify, but say nothing about adding @NullMarked/@Nullable to existing public API. Retrofitting annotations onto a class that already ships has compatibility traps that are not obvious from the current rules. In the review of #26320 (Element), each of these came up as a separate finding, several only after an earlier suggestion turned out to break something too:
- Kotlin source compatibility. Kotlin treats JSpecify annotations as strict, so marking existing getters
@Nullable(getAttribute,getParent,getProperty, …) breaks Kotlin callers such asel.parent.tag. Removing the annotation later breaks the adapted callers the other way. The change is source-breaking in a minor release, which affects the risk assessment and needs a release note. - Generic wildcards vs. overriding. Changing a parameter of a non-final method from
SerializableFunction<UI, Registration>toSerializableFunction<UI, ? extends @Nullable Registration>makes existing overrides fail with "name clash: … have the same erasure, yet neither overrides the other". Putting the annotation on the type argument, without a wildcard, avoids that. - Overload delegation. Splitting
getProperty(String)fromgetProperty(String, String)to give them different nullness changed which overload a subclass override affects.getProperty(name, null)is also a common idiom, so a non-nulldefaultValuecontract does not hold. @NullUnmarkedscope.@NullUnmarkedon a method turns off checking for every parameter and the return type, not just the one generic argument that was problematic. Annotating the type argument (Signal<@Nullable String>) keeps the rest checked.- Consistency across sibling methods.
addJsInitializeraccepted a@Nullablevarargs array whileexecuteJs/callJsFunctionstill threw an NPE for it. package-info.java. The package (com.vaadin.flow.dom) had nopackage-info.java, so there was nowhere for package-level@NullMarked.
Suggested fix
Add a short "Annotating existing API" subsection under "Nullability discipline" in guidelines/design.md (and a pointer in CONVENTIONS.md), covering:
- Adding
@Nullableto the return value or parameter of an existing public method is a Kotlin source break. Call it out as one in the PR risk section and in the release notes. - Never introduce a wildcard (
? extends @Nullable T) into the parameter type of an overridable method. Annotate the type argument instead (Function<UI, @Nullable Registration>), or keep the signature and document that null is allowed. - Keep existing overload delegation as it is. Don't split overloads to give them different nullness.
- Prefer annotating the specific type argument over
@NullUnmarked. If@NullUnmarkedis unavoidable, reference one tracking issue instead of repeating the same comment on every method. - Keep nullness of the same parameter consistent across sibling methods (e.g. all
executeJs-style varargs either accept or reject anullarray). - Add
package-info.javawith@NullMarkedwhen annotating the first class in a package.
Activity
totally-not-ai commentedon Nov 2, 2026
Thanks for the write-up. This is a valid documentation gap: the "Nullability discipline" section of
guidelines/design.mdand the Nullability rules inCONVENTIONS.mdonly cover annotating new code, and say nothing about the compatibility traps of retrofitting JSpecify annotations onto API that already ships.All six points hold up technically:
@Nullableto an existing return/parameter type is a source break for Kotlin callers even though Java callers are unaffected.F<UI, R>toF<UI, ? extends @Nullable R>on an overridable method keeps the erasure but changes the signature, so existing overrides hit "same erasure, yet neither overrides the other";F<UI, @Nullable R>avoids it.@NullUnmarkedon a method disables checking for all parameters and the return type.com.vaadin.flow.domhas nopackage-info.javayet, so there is nowhere for package-level@NullMarked.Since this is docs-only and the content is clear-cut, I've opened a draft PR: #26793. Following the repo's split between rules and reasoning, it adds the checkable rules to the Nullability section of
CONVENTIONS.mdand a new "Annotating existing API" subsection under "Nullability discipline" inguidelines/design.mdthat explains each rule with the failure it prevents.