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
By default, NullAway simply trusts @Contract annotations and does not verify that they match the behavior of the annotated method. Passing the CheckContracts flag enables checking of contracts, which should add more safety. If you all try this and run into issues we are happy to look into them on the NullAway side. We may switch the defaults and make contract checking an opt-out setting in the future rather than opt-in.
With this implemented, I think I may have found a contract-checking bug triggered by this code:
/** * Parse certificates from the specified string. * @param text the text to parse * @return the parsed certificates */@Contract("!null -> !null")
static@NullableList<X509Certificate> parse(@NullableStringtext) {
if (text == null) {
returnnull;
}
CertificateFactoryfactory = getCertificateFactory();
List<X509Certificate> certs = newArrayList<>();
readCertificates(text, factory, certs::add);
Assert.state(!CollectionUtils.isEmpty(certs), "Missing certificates or unrecognized format");
returnList.copyOf(certs);
}
Compilation fails:
PemCertificateParser.java:63: error: [NullAway] Method parse has @Contract(!null -> !null), but this appears to be violated, as a @Nullable value may be returned when parameter text is non-null.
return null;
I see similar problems for other !null -> !null contracts:
PemContent.java:164: error: [NullAway] Method of has @Contract(!null -> !null), but this appears to be violated, as a @Nullable value may be returned when parameter text is non-null.
return (text != null) ? new PemContent(text) : null;
ConfigurationProperty.java:131: error: [NullAway] Method of has @Contract(_, !null -> !null), but this appears to be violated, as a @Nullable value may be returned when parameter value is non-null.
return null;
ConfigurationProperty.java:140: error: [NullAway] Method of has @Contract(_, _, !null, _ -> !null), but this appears to be violated, as a @Nullable value may be returned when parameter value is non-null.
return null;
ConfigurationPropertiesBean.java:292: error: [NullAway] Method create has @Contract(_, _, !null -> !null), but this appears to be violated, as a @Nullable value may be returned when parameter bindTarget is non-null.
return (bindTarget != null) ? new ConfigurationPropertiesBean(name, instance, bindTarget) : null;
DefaultApplicationContextFactory.java:87: error: [NullAway] Method getFromSpringFactories has @Contract(_, _, !null -> !null), but this appears to be violated, as a @Nullable value may be returned when parameter defaultResult is non-null.
return (defaultResult != null) ? defaultResult.get() : null;
CollectionToDelimitedStringConverter.java:63: error: [NullAway] Method convert has @Contract(!null, _, _ -> !null), but this appears to be violated, as a @Nullable value may be returned when parameter source is non-null.
return null;
Apologies if we've misunderstood the contract syntax but these all look like false-positive violations and may have the same underlying cause. Please let me know if we should open a NullAway issue for this.
This looks like a NullAway bug at first glance. Sorry about it. I may not be able to fix immediately, so for now I suggest disabling contract checking. If you could open a bug on the NullAway repo I can take a look when I have time.
Activity
[-]Suggestion: enable contract checking[/-][+]Enable contract checking[/+]wilkinsona commentedon Jan 20, 2026
Thanks for the suggestion, @msridhar.
With this implemented, I think I may have found a contract-checking bug triggered by this code:
Compilation fails:
I see similar problems for other
!null -> !nullcontracts:PemContent.java:164:
ConfigurationProperty.java:131:
ConfigurationProperty.java:140:
ConfigurationPropertiesBean.java:292:
DefaultApplicationContextFactory.java:87:
CollectionToDelimitedStringConverter.java:63:
Apologies if we've misunderstood the contract syntax but these all look like false-positive violations and may have the same underlying cause. Please let me know if we should open a NullAway issue for this.
Revert "Enable contract checking"
wilkinsona commentedon Jan 20, 2026
I'm wondering if we've misunderstood
@Contract. NullAway reports an error for this method which seems pretty straightforward in terms of nullability:These variants also report a contract violation:
Both of these do not report a violation:
Enable contract checking
msridhar commentedon Jan 20, 2026
This looks like a NullAway bug at first glance. Sorry about it. I may not be able to fix immediately, so for now I suggest disabling contract checking. If you could open a bug on the NullAway repo I can take a look when I have time.
wilkinsona commentedon Jan 20, 2026
Thanks, @msridhar. I've opened apache/nullaway#1440.