You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Contract checking does not check for proper overriding #803
Our checking of @Contract annotations (which is off by default) does not check for correct method overriding. So, if a supertype method has a particular @Contract, we do not check that overriding methods adhere to the @Contract, which could lead to missed NPE bugs. Originally discussed here.
Still applies on master (5023d67). With CheckContracts=true, ContractCheckHandler checks a method only against its own @Contract, so an override that drops or weakens the supertype's contract is silent while callers typed as the supertype keep trusting it. #1758 and #1771 did not change this: they make nullImpliesNull library models apply to overrides at call sites, which per the comment above the eventual check should also cover. The field-contract handlers already have the shape this would follow (RequiresNonNullHandler.validateOverridingRules, EnsuresNonNullIfHandler.validateOverridingRules).
Open design points for whoever picks this up: whether an override with no @Contract inherits the supertype's clauses (and its body is checked against them) or is reported for missing them; how to decide that an override's own @Contract implies the supertype's (clause-by-clause match, or only the checkable _/null/!null -> !null subset that ContractCheckHandler verifies today).
Activity
Document that a nullImpliesNull model applies to overriding methods (#…
msridhar commentedon Aug 29, 2026
Note from #1758 that whatever support we build here should also account for library models that are equivalent to contracts.
vlsi commentedon Oct 22, 2026
Still applies on master (5023d67). With
CheckContracts=true,ContractCheckHandlerchecks a method only against its own@Contract, so an override that drops or weakens the supertype's contract is silent while callers typed as the supertype keep trusting it. #1758 and #1771 did not change this: they makenullImpliesNulllibrary models apply to overrides at call sites, which per the comment above the eventual check should also cover. The field-contract handlers already have the shape this would follow (RequiresNonNullHandler.validateOverridingRules,EnsuresNonNullIfHandler.validateOverridingRules).Open design points for whoever picks this up: whether an override with no
@Contractinherits the supertype's clauses (and its body is checked against them) or is reported for missing them; how to decide that an override's own@Contractimplies the supertype's (clause-by-clause match, or only the checkable_/null/!null -> !nullsubset thatContractCheckHandlerverifies today).Reproducer (NullAway 5023d67, JDK 21)
Flags:
-XepOpt:NullAway:AnnotatedPackages=com.uber-XepOpt:NullAway:CheckContracts=trueObserved: no diagnostic. Expected: an error in
Sub.mand onSub2.m's contract.