Add wildcard bounds to Java DSL parameters that are needlessly invariant
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
Research direction
Read the Java DSL signatures for Source, Sink, Flow, SubFlow, SubSource, and FlowWithContext, plus persistence-typed javadsl Effect.persist(events). Start with the Java tests that exercise these parameters and add narrower-typed variables to verify they compile. Done means the listed wildcard bounds are consistent, those tests pass, and mimaReportBinaryIssues stays clean for stream and persistence-typed.
Written by the indexing model from the issue text.
Description
Java generics are invariant, so several Java DSL parameters reject values that a Java user would reasonably expect to pass, typically a variable whose declared type is a narrower generic (e.g. List<Source<T, NotUsed>> or List<ItemAdded>). Lambdas mostly adapt to the target type; pre-typed variables, fields and method references do not.
Adding wildcard bounds only changes the generic signature, not the erased descriptor, so this should be binary compatible (MiMa clean) and source compatible for existing Java and Scala callers.
Parameters that reject ordinary Java variables
| Location | Today | Suggested |
|---|---|---|
javadsl.Source.combine rest |
java.util.List[Source[T, ? <: Any]] |
java.util.List[? <: Graph[SourceShape[T], ?]] |
javadsl.Source.zipN, zipWithN |
java.util.List[Source[T, ? <: Any]] |
java.util.List[? <: Graph[SourceShape[T], ?]] |
javadsl.Source.mergePrioritizedN |
java.util.List[Pair[Source[T, ? <: Any], Integer]] |
java.util.List[? <: Pair[? <: Graph[SourceShape[T], ?], Integer]] |
javadsl.Sink.combine rest |
java.util.List[Sink[U, ?]] |
java.util.List[? <: Graph[SinkShape[U], ?]] |
persistence-typed javadsl.Effect.persist(events) |
java.util.List[Event] |
java.util.List[? <: Event] |
For example, List<Source<Integer, NotUsed>> sources = ...; Source.zipN(sources) does not compile today, and neither does passing a List<ItemAdded> to Effect().persist(...) when the behavior's event type is Event. The newer list-based Source.combine / Sink.combine overloads and mergeAll already use java.util.List[? <: Graph[...]], and the scaladsl persist takes a covariant immutable.Seq[Event].
Inconsistencies with sibling operators
The same operator has a bound in one class but not in its siblings:
mapConcat:Source,SourceWithContextandFlowWithContextuseFunction[Out, ? <: java.lang.Iterable[T]];Flow,SubFlowandSubSourcetake a plainjava.lang.Iterable[T].statefulMapConcat: the inner function returns a plainjava.lang.Iterable[T]inSource,Flow,SubFlowandSubSource; should be? <: java.lang.Iterable[T].recoverWith/recoverWithRetries:SourceandFlowrecoverWith(pf)use? <: Graph[SourceShape[Out], NotUsed];SubFlow,SubSourceandFlow.recoverWithRetriesdo not.fanInStrategy/fanOutStrategy:Source.combine(first, second, rest, ...)usesFunction[Integer, ? <: Graph[...]]; the list-basedSource.combineoverload andSink.combine/Sink.combineMatdo not.
Tests
Java tests should pass a variable of the narrower type (which fails to compile before the change), and mimaReportBinaryIssues for stream and persistence-typed should stay clean.
- Dominant language
- Scala
- Stars
- 1.7k
- Forks
- 212
- Avg merge
- 20h 44m
- Merged PRs (30d)
- 104
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/pekko
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/pekko#1840 · 8 comments ·
Maintainers usually reply within 1 day
-
Coordinator singleton lease loss permanently stops the local ShardRegion while the node is still UpPossibly taken @He-Pin claimed this 4 days ago. Openbug cluster
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
enhancement flaky make-tests-easier-to-run
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Maintainers usually reply within 1 day
-
build enhancement github_actions
Difficulty 3/5 1-2 days Newbie friendliness 70/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 73/100
lichess-org/lila#22298 ·
Maintainers usually reply within 1 day
-
Task 🔧
Difficulty 1/5 Under an hour Newbie friendliness 88/100
valkey-io/valkey-glide#7455 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
master is red: two chapter-title overrides orphaned by the plan update, and both titles are untranslated in compendium-enPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
lunduniversity/introprog#1005 · 1 comment ·
Maintainers usually reply within 7 days