Skip to content

Fix ByteString1C serialization to use SerializationProxy#2929

Merged
pjfanning merged 2 commits intoapache:mainfrom
pjfanning:copilot/fix-serialization-issues-byte-string
Apr 28, 2026
Merged

Fix ByteString1C serialization to use SerializationProxy#2929
pjfanning merged 2 commits intoapache:mainfrom
pjfanning:copilot/fix-serialization-issues-byte-string

Conversation

@pjfanning
Copy link
Copy Markdown
Member

Motivation

ByteString1C — the sole concrete implementation of CompactByteString — lacked a writeReplace() method. This caused Java serialization to serialize it directly using @SerialVersionUID(3956956327691936932L) rather than delegating to the SerializationProxy that both ByteString1 and ByteStrings use. Any change to the class structure (e.g. moving to a different package) would make previously serialized ByteString1C data unreadable due to SerialVersionUID mismatches. All CompactByteString factory methods (CompactByteString.apply(...), CompactByteString.fromArray(...), etc.) return ByteString1C, so all of them were affected.

Modification

Add protected def writeReplace(): AnyRef = new SerializationProxy(this) to ByteString1C, matching the pattern already present in ByteString1 and ByteStrings. All infrastructure (byteStringCompanion, writeToOutputStream, SerializationIdentity) was already in place on ByteString1C; the only missing piece was the hook.

Result

All three concrete ByteString types now consistently serialize via SerializationProxy. The serialized form no longer embeds the ByteString1C class descriptor, making the format resilient to class renaming/moving.

Tests

  • New test: ByteString1C serializes via SerializationProxy not directly — asserts the raw serialized bytes do not contain the string "ByteString1C" (i.e. the proxy class descriptor is written, not the raw implementation class).
  • New test: CompactByteString instances serialize via SerializationProxy — same assertion for CompactByteString.apply() and CompactByteString("hello") factories.
  • New test: each ByteString concrete type round-trips via serialization — explicit round-trip for ByteString1C, ByteString1, and ByteStrings.

Tests: run locally not possible (sbt not installed in sandbox). Tests added and reviewed; CI will validate.

References

None - serialization proxy consistency fix for ByteString1C / CompactByteString

Copilot AI and others added 2 commits April 28, 2026 06:47
ByteString1C lacked a writeReplace() method, causing it to be serialized
directly (using @serialversionuid(3956956327691936932L)) rather than via
the SerializationProxy used by ByteString1 and ByteStrings. This led to
SerialVersionUID mismatches when deserializing ByteString1C (and all
CompactByteString instances, which are backed by ByteString1C).

Add writeReplace() to ByteString1C so all three concrete ByteString types
consistently route through SerializationProxy on serialization.

Add three new tests:
- Verify ByteString1C serialized bytes do not contain the class name
  "ByteString1C" (i.e. the proxy is used, not direct serialization)
- Verify CompactByteString.apply() instances also serialize via proxy
- Verify round-trip serialization for all three concrete types

Agent-Logs-Url: https://github.com/pjfanning/incubator-pekko/sessions/a999ad23-eb25-41ef-b082-8e78f5b9353b

Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Copy link
Copy Markdown
Member

@He-Pin He-Pin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Reviewed the ByteString1C serialization proxy hook against the existing ByteString1/ByteStrings serialization path and ran local ByteString serialization tests.

@pjfanning pjfanning merged commit 6313843 into apache:main Apr 28, 2026
9 checks passed
@pjfanning pjfanning added this to the 2.0.0-M2 milestone Apr 29, 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.

3 participants