Repository navigation
fix: leave eventTime unset until event() sends it - #4
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Defaulting a null eventTime by replacing the event with a base ApiEvent drops fields from caller-provided subclasses, causing payload data loss.
1 open issue
What changed in this PR
This PR moves default tracking timestamps from event construction to sending, so reused events receive a fresh timestamp without modifying the caller’s object.
Changes:
- Leave
eventTimenull in the two-argumentApiEventconstructor. - Apply a default timestamp to a copy when sending an event.
- Document the behavior and test event reuse and explicit timestamps.
| File | Description |
|---|---|
src/test/java/com/spreedly/composer/ComposerIntegrationTest.java |
Tests fresh timestamps on reuse and preservation of explicit timestamps. |
src/test/java/com/spreedly/composer/api/ApiTest.java |
Expects a null timestamp after construction. |
src/main/java/com/spreedly/composer/api/ComposerServices.java |
Defaults the timestamp on a copy before serialization. |
src/main/java/com/spreedly/composer/api/ApiEvent.java |
Removes timestamp initialization from the two-argument constructor. |
CHANGELOG.md |
Documents send-time defaulting without caller mutation. |
Review effort: Balanced
Samy-O7
left a comment
There was a problem hiding this comment.
Checked before approving, at e8a6bc0: event() no longer changes the caller's ApiEvent, and the constructor no longer sets the time, so a reused event gets a fresh time on each call. It now always sends just type, data and eventTime, like the Python SDK. That settles the subclass case Copilot raised, and the CHANGELOG says so. Checkpoints aren't affected because they use Event. Two of the new tests would fail on main: the constructor's timestamp makes both sends identical, and a subclass's extra field gets sent. I reviewed this by reading the code, without running Java locally. CI passes on Java 11 and 25, and its logs show the new tests ran.
One optional note: in protect-core 1.2.0, eventTime was a Date. It's now a Long in milliseconds, and the CHANGELOG doesn't mention that yet.

Changes
ApiEvent(type, data)leaveseventTimenullinstead of setting it to the time the object is createdeventTimeisnull,event()sends the current time without setting it on the caller'sApiEvent, so a reused event gets a fresh time on each callevent()sends onlytype,dataandeventTime, so fields added in anApiEventsubclass aren't sent