pjfanning opened a new pull request, #3720:
URL: https://github.com/apache/pekko/pull/3720
### Motivation
Java generics are invariant, so the javadsl APIs of the typed modules reject
pre-typed function values a Java user would reasonably pass, for example a
`Function<Object, Behavior<String>>` for `Behaviors.receiveMessage`, a handler
over `CharSequence` for `onMessage(String.class, ...)`, a `Function<Object,
String>` for `ActorContext.messageAdapter`, or a `BiFunction` over a supertype
of the state for an event sourced command handler. Lambdas adapt to the target
type; variables, fields and shared handlers do not.
#3713, #3714, #3717 and #3719 cover the stream javadsl and #3718 covers
stream-typed. This is the rest of item 3 in the follow-up comment on #3712.
### Modification
- Widen function-typed parameters (`japi.function`
`Function`/`Function2`/`Creator`/`Predicate`/`Procedure` and
`java.util.function`
`Function`/`BiFunction`/`Supplier`/`Consumer`/`BiConsumer`/`Predicate`) in the
javadsl of:
- **actor-typed**: `Behaviors` (`setup`, `receiveMessage`, `withTimers`,
`withStash`, `withMdc`, …), `BehaviorBuilder`/`ReceiveBuilder` handlers,
`ActorContext` (`messageAdapter`, `ask`, `askWithStatus`, `pipeToSelf`),
`AskPattern`, `Adapter.props`, `Routers`, `StashBuffer`
- **actor-testkit-typed**: `TestProbe` (`fishForMessage`, `awaitAssert`,
`within`), `LoggingTestKit`, `BehaviorTestKit.runAsk*`
- **cluster-typed**: `ReplicatorMessageAdapter`, `DistributedData`
- **cluster-sharding-typed**: `ClusterSharding`/`EntityRef.ask`,
`ShardedDaemonProcess`
- **persistence-typed**: command/event/signal handler builders (classic
and durable state), `Effect` `thenRun`/`thenReply`, `ReplicatedEventSourcing`
- **persistence-testkit**: `EventSourcedBehaviorTestKit`,
`DurableStateBehaviorTestKit`
- Inputs take `? >:` and results `? <:`; no bound is added where it cannot
widen anything (e.g. `? <:` on `Boolean` or `String`).
- Only final classes, objects and `@DoNotInherit` types are changed, so no
user subclass or override can break; Pekko's internal implementations are
updated to match. Deliberately **not** changed because users or plugins
implement them: the classic `testkit` `TestKit` and `EventFilter`,
`coordination` `Lease`, and the persistence-query `@ApiMayChange` query traits
(and `EventsBySliceFirehoseQuery`, which implements one of them).
- The persistence-typed handler builders keep their internal invariant
storage; widened handlers and predicates are narrowed where they are stored,
and Scala lambdas passed to the overloaded `onCommand`/`onEvent` get explicit
types so Scala 2 overload resolution still works.
- Add MiMa excludes (`IncompatibleSignatureProblem` only) per module.
### Result
Java callers can pass function values typed over a supertype of the input or
a subtype of the result without casts. Erasure is unchanged, so the change is
binary compatible.
### Tests
- New directional tests that only compile with the widened signatures:
`FunctionWildcardBoundsTest` (actor-typed-tests: `receiveMessage`,
`BehaviorBuilder.onMessage`, `messageAdapter`, `TestProbe.fishForMessage`) and
`EventSourcedBehaviorJavaDslTest.acceptHandlersTypedOverSupertypes`
(`onAnyCommand`, `onAnyEvent`, `thenRun`). Not run locally - left to CI.
- `sbt compile` for the changed modules on Scala 2.13 and `++3.3.8` - passed
- `sbt Test/compile` for `actor-typed-tests`, `actor-testkit-typed`,
`cluster-typed`, `cluster-sharding-typed`, `persistence-typed`,
`persistence-typed-tests`, `persistence-testkit` (Scala 2.13) - passed
- `sbt mimaReportBinaryIssues` for the changed modules - passed with the
added excludes
- `docs` and Scala 3 test compilation left to CI
### References
Refs #3712, #3718
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]