Skip to content

refactor: replace deprecated collection aliases in internal io code - #3467

Merged
pjfanning merged 1 commit into
apache:mainfrom
pjfanning:deprecated-collection-aliases
Aug 25, 2026
Merged

refactor: replace deprecated collection aliases in internal io code#3467
pjfanning merged 1 commit into
apache:mainfrom
pjfanning:deprecated-collection-aliases

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Motivation

scala.collection.GenTraversableOnce and scala.collection.immutable.Traversable are deprecated aliases retained for the 2.12 migration — they resolve to IterableOnce and immutable.Iterable. Three internal sites still use them, and each carries a @nowarn("msg=deprecated") to silence the resulting warning:

site alias
DnsMessage.scala:170Message.parse's flattener implicit GenTraversableOnce
TcpConnection.scala:226completeConnect immutable.Traversable
TcpIncomingConnection.scala:33 — constructor immutable.Traversable

Modification

Use the current names and drop the three @nowarn suppressions.

The suppressions are the substantive part of this change. @nowarn("msg=deprecated") on a class or method silences every deprecation warning in its scope, not just the one it was added for. I verified all three were stale by removing them and recompiling — the code builds clean without them. Left in place they would keep hiding unrelated deprecation warnings in those files indefinitely; in TcpIncomingConnection the annotation sits on the whole class.

Scope and safety

All three sites are internal:

  • Message is private[internal]
  • TcpConnection and TcpIncomingConnection are private[io], and the only two callers of completeConnect (TcpIncomingConnection.scala:46, TcpOutgoingConnection.scala:112) are in the same package

The aliases are identical types, so this is behaviour preserving — no erasure change, no signature change visible outside io.

What is deliberately not in this PR

The public API still uses immutable.Traversable, in Tcp.scala:138,167, Udp.scala:118,139, UdpConnected.scala:112 and stream/scaladsl/Tcp.scala:144,186,220. Those are left alone on purpose: the Scala pickle signature changes even though erasure does not, and Udp.SimpleSender is a case class so copy and unapply would change with it. That is a considered API change for a major release, gated on +mimaReportBinaryIssues, not a drive-by refactor. Their @nowarns stay for the same reason.

Tests

No new tests. This is a type-alias substitution with no behaviour change, and the affected paths already have coverage — MessageSpec exercises Message.parse and therefore the flattener implicit directly.

  • actor-tests/testOnly org.apache.pekko.io.dns.* — 60 tests pass
  • actor-tests/testOnly org.apache.pekko.io.dns.internal.* org.apache.pekko.io.TcpConnectionSpec org.apache.pekko.io.TcpIntegrationSpec — 94 pass
  • sbt actor/mimaReportBinaryIssues — clean
  • sbt ++3.3.8 actor/compile — passes. Worth calling out: GenTraversableOnce and IterableOnce differ in availability between Scala 2.13 and 3, and DnsMessage.scala is a single shared source file rather than a cross-version variant, so Scala 3 was the real risk in this change.
  • scalafmt run

References

Last of the items from the Java 8 / Scala 2.12 legacy sweep, following #3465 and #3466.

`GenTraversableOnce` and `immutable.Traversable` are deprecated aliases
for `IterableOnce` and `immutable.Iterable` respectively, kept for the
2.12 migration. Three internal sites still use them, each carrying a
`@nowarn("msg=deprecated")` to suppress the resulting warning:

  - Message.parse's `flattener` implicit conversion in DnsMessage
  - TcpConnection.completeConnect
  - the TcpIncomingConnection constructor

Use the current names and drop the suppressions, which are now stale.
That is the substantive part: an `@nowarn("msg=deprecated")` on a class
or method silences every deprecation warning in its scope, so leaving
them would keep hiding warnings unrelated to the aliases.

All three sites are internal -- `Message` is `private[internal]`, and
`TcpConnection` and `TcpIncomingConnection` are `private[io]` -- so no
public signature changes. The aliases are identical types, so this is
behaviour preserving.

The public API still uses `immutable.Traversable` in Tcp, Udp,
UdpConnected and stream's Tcp. Those are deliberately left alone: the
Scala signature would change, and `Udp.SimpleSender` is a case class, so
`copy` and `unapply` would change with it. They belong in a considered
API change, not here.
@pjfanning
pjfanning merged commit c10661e into apache:main Aug 25, 2026
10 checks passed
@pjfanning pjfanning added this to the 2.0.0-M5 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants