Fix Java unchecked warnings in stream testkit fluent API (#2625)#2725
Merged
Fix Java unchecked warnings in stream testkit fluent API (#2625)#2725
Conversation
Use Scala's `this.type` return type instead of abstract type member `Self` to fix raw type erasure in bytecode signatures. This is a root-cause fix that eliminates unchecked warnings in Java without any boilerplate overrides. Root cause: `type Self <: ManualProbe[I]` erased to raw `ManualProbe` in bytecode (no generic Signature attribute), causing Java to see raw types. `this.type` makes the Scala compiler emit `ManualProbe<TI;>` (parameterized) in the bytecode Signature attribute, so Java sees proper generic types. Changes: - Remove `type Self` abstract type members from ManualProbe/Probe classes - Change all fluent method return types from `Self` to `this.type` - Replace `self` references with `this` - Fix ScalaDoc links: TestSubscriber → TestSubscriber.Probe, TestPublisher → TestPublisher.Probe - Fix typo: "JAVA PAI" → "JAVA API" Binary compatible: erased JVM return types unchanged (MiMa safe). Only generic Signature attribute metadata changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When Java code uses the stream testkit fluent API (e.g.,
TestSink.create(system),probe.expectNext()), the compiler emits unchecked warnings because Scala's abstract type membertype Self <: ManualProbe[I]erases to a rawManualProbetype in bytecode — no genericSignatureattribute is emitted. Java reads these bytecode signatures and sees raw types, triggering-Xlint:uncheckedwarnings on every chained call.See: #2625
Modification
Root-cause fix using
this.type— Replace the abstract type member pattern with Scala's singletonthis.typereturn type:type Selfabstract type members fromTestPublisher.ManualProbe,TestPublisher.Probe,TestSubscriber.ManualProbe, andTestSubscriber.ProbeSelftothis.type— this makes the Scala compiler emit parameterized generic signatures in bytecodeselfreferences (this.asInstanceOf[Self]) with plainthisIncompatibleSignatureProblementries in bothManualProbeandProbeclasses (only generic Signature metadata changes — erased JVM types are unchanged)TestSubscriber→TestSubscriber.Probe,TestPublisher→TestPublisher.ProbeWhy
this.typeworksManualProbe/Probe(unchanged — binary compatible)IncompatibleSignatureProblem— these are Signature-only changes, erased types are identicalWhy this is better than method overrides
The previous approach required 27+ boilerplate override methods in
Probeclasses to narrow return types. This fix addresses the root cause in the base class itself — zero overrides needed, and any future fluent methods added toManualProbewill automatically have correct generic signatures.Result
-Xlint:uncheckedReferences
StreamTestKit.scala,TestSink.scala,TestSource.scala,fix-java-unchecked-warnings.excludes