Repository navigation
Skip FluentFutureHandler in JSpecify mode - #2066
Conversation
FluentFutureHandler treats the return of a Guava Function or AsyncFunction lambda passed to transform, transformAsync, catching, or catchingAsync of Futures or FluentFuture as nullable. Its Javadoc calls it a workaround for missing generics support. In JSpecify mode, generic method inference now covers these calls: `ListenableFuture<@nullable String> r = Futures.transform(in, x -> null, e)` is accepted without the handler, and with a non-null target the inference reports `type variable O constrained to be both @nonnull and @Nullable` with or without it. In that mode the handler only hid the `returning @nullable expression` error on a `return null` inside a block lambda. For transformAsync and catchingAsync that error is real, because an AsyncFunction returns the future itself. Register the handler only outside JSpecify mode, the same split apache#2040 makes for the Guava functional-interface library models. User-visible: In JSpecify mode, `return null` in a block lambda passed to these methods is reported as `returning @nullable expression from method with @nonnull return type` when the inferred result type is non-null, and always for transformAsync and catchingAsync. In JSpecify mode, the ExtraFuturesClasses option has no effect: a lambda passed to a configured class gets its return nullability from that class's type parameters. Not changed: outside JSpecify mode, the handler and ExtraFuturesClasses work as before. Assisted-by: Claude Code (claude-opus-5-5)
|
No actionable comments were generated in the recent review.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2066 +/- ##
=========================================
Coverage 89.20% 89.21%
Complexity 38 38
=========================================
Files 119 119
Lines 12771 12772 +1
Branches 2589 2590 +1
=========================================
+ Hits 11393 11394 +1
Misses 623 623
Partials 755 755 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
FluentFutureHandler treats the return of a Guava Function or AsyncFunction lambda passed to transform, transformAsync, catching, or catchingAsync of Futures or FluentFuture as nullable. Its Javadoc calls it a workaround for missing generics support. In JSpecify mode, generic method inference now covers these calls:
ListenableFuture<@Nullable String> r = Futures.transform(in, x -> null, e)is accepted without the handler, and with a non-null target the inference reportstype variable O constrained to be both @NonNull and @Nullablewith or without it. In that mode the handler only hid thereturning @Nullable expressionerror on areturn nullinside a block lambda. For transformAsync and catchingAsync that error is real, because an AsyncFunction returns the future itself.Register the handler only outside JSpecify mode, the same split #2040 makes for the Guava functional-interface library models.
User-visible:
In JSpecify mode,
return nullin a block lambda passed to these methods is reported asreturning @Nullable expression from method with @NonNull return typewhen the inferred result type is non-null, and always for transformAsync and catchingAsync.In JSpecify mode, the ExtraFuturesClasses option has no effect: a lambda passed to a configured class gets its return nullability from that class's type parameters.
Not changed: outside JSpecify mode, the handler and ExtraFuturesClasses work as before.
The new JSpecify-mode tests in
NullAwayGuavaParametricNullnessTestsfail with the handler registered: everyreturning @Nullable expressionexpectation goes unseen.:guava-recent-unit-tests:test,:nullaway:test,:nullaway:buildWithNullAwaypass;:nullaway:pitestDiffkills the one mutant on the changed lines.Assisted-by: Claude Code (claude-opus-5-5)
🤖 Generated with Claude Code
Summary by CodeRabbit
FluentFuturehandling differs in JSpecify mode, where generic method inference determines whether a lambda may returnnull.