Repository navigation
Strip parentheses before the futures and gRPC handlers match an argument - #2010
Conversation
A parenthesized argument hid a lambda from `FluentFutureHandler` and a `Metadata.Key` field from `GrpcHandler`, so both reported warnings that the same code without the parentheses does not. `Futures.transform(in, (s -> { return null; }), e)` reported `returning @nullable expression from method with @nonnull return type`, and `if (h.containsKey((K))) { take(h.get(K)); }` reported `passing @nullable parameter 'h.get(K)' where @nonnull is required`.
`FluentFutureHandler` now strips parentheses from each argument before comparing it with the enclosing lambda, and `GrpcHandler` strips them from the `containsKey` argument before resolving its symbol. A lambda nested deeper, such as an operand of a conditional passed to `Futures.transform`, is still not an argument of that call and still gets the Guava `Function` non-null return.
The other handlers need no change for parentheses: `ContractHandler` reads a boolean argument through `ASTHelpers.constValue`, which sees through the parentheses, `StreamNullabilityPropagator`, `SynchronousCallbackHandler`, and `EnsuresNonNullIfHandler` already strip them, and the remaining handlers read dataflow nodes, which carry no parentheses. The parentheses divergences in `GenericsChecks` (a parenthesized lambda assigned to a field, and a parenthesized `map` argument after `filter(Objects::nonNull)`) are outside the handlers and outside this change.
The new tests fail on master with the warnings above. Controls with the same parentheses still report: a lambda passed to a method outside the Futures APIs, a lambda inside a conditional, a lambda in a field initializer, and `get` of a key other than the one `containsKey` checked.
This is a variation of uber#1993.
Assisted-by: Claude Code (claude-opus-5-5)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe gRPC handler now strips parentheses from the first Suggested reviewers: Priority: ⬇️ Low Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2010 +/- ##
============================================
+ Coverage 88.74% 88.76% +0.01%
Complexity 38 38
============================================
Files 118 118
Lines 12548 12551 +3
Branches 2543 2543
============================================
+ Hits 11136 11141 +5
+ Misses 643 642 -1
+ Partials 769 768 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A parenthesized argument hid a lambda from
FluentFutureHandlerand aMetadata.Keyfield fromGrpcHandler, so both reported warnings that the same code without the parentheses does not.Futures.transform(in, (s -> { return null; }), e)reportedreturning @Nullable expression from method with @NonNull return type, andif (h.containsKey((K))) { take(h.get(K)); }reportedpassing @Nullable parameter 'h.get(K)' where @NonNull is required.FluentFutureHandlernow strips parentheses from each argument before comparing it with the enclosing lambda, andGrpcHandlerstrips them from thecontainsKeyargument before resolving its symbol. A lambda nested deeper, such as an operand of a conditional passed toFutures.transform, is still not an argument of that call and still gets the GuavaFunctionnon-null return.The other handlers need no change for parentheses:
ContractHandlerreads a boolean argument throughASTHelpers.constValue, which sees through the parentheses,StreamNullabilityPropagator,SynchronousCallbackHandler, andEnsuresNonNullIfHandleralready strip them, and the remaining handlers read dataflow nodes, which carry no parentheses. The parentheses divergences inGenericsChecks(a parenthesized lambda assigned to a field, and a parenthesizedmapargument afterfilter(Objects::nonNull)) are outside the handlers and outside this change.The new tests fail on master with the warnings above. Controls with the same parentheses still report: a lambda passed to a method outside the Futures APIs, a lambda inside a conditional, a lambda in a field initializer, and
getof a key other than the onecontainsKeychecked.This is a variation of #1993.
Assisted-by: Claude Code (claude-opus-5-5)
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
FuturesandFluentFuturetransformations, with nullable-return diagnostics retained in contexts that require non-null values.Tests