Repository navigation
Conversation
StartingFrom accepted a null position as a legacy synonym for "start from the beginning", while TrackingToken.FIRST exists specifically to express that explicitly. Having two spellings of the same request meant consumers only had to handle one of them correctly to look right in tests, while the other silently broke (e.g. type-check exceptions, wrong resolved sequence). Normalize null to TrackingToken.FIRST in the constructor instead, so position() never returns null and there is exactly one way to express "start from the beginning" going forward. Also drops the now-unreachable null-position exceptions in withCriteria/or, and simplifies a matching null-position branch in the AsyncInMemoryStreamableEventSource test fixture. Also fixes AsyncInMemoryStreamableEventSource.latestToken() to return a real token instead of null for an empty store, matching firstToken()'s contract; this surfaced while adding TrackingToken.LATEST coverage for a consumer of this fixture.
1afc0d7 to
c8f3f0e
Compare
| * @author Steven van Beelen | ||
| * @since 5.0.0 | ||
| */ | ||
| record StartingFrom(@Nullable TrackingToken position) implements StreamingCondition { |
There was a problem hiding this comment.
I find this confusing, as this mixes two concerns: The StartingFrom property position is NonNull as it defaults to FIRST. The constructor argument StartingFrom() is nullable.
Using the record like this makes the property nullable, leading to null conflict in position() (which returns the nullable property as a non-null getter).
So: I guess javas record behaviour does not fit and I would vouch for turning this into a class:
public final class StartingFrom implements StreamingCondition {
private final TrackingToken position;
public StartingFrom(@Nullable TrackingToken position) {
this.position = position != null ? position : TrackingToken.FIRST;
}
/*
* Explicitly overridden so the accessor does not inherit the @Nullable annotation carried by the position
* record component below, which is only there to let the compact constructor accept a null input.
*/
@Override
public TrackingToken position() {
return position;
}
....
}There was a problem hiding this comment.
It could indeed be a class to make this more clear, I think that would be backwards compatible, but I have to check.
jangalinski
left a comment
There was a problem hiding this comment.
One comment on the nullability of the record class that could be changed.
And the mentioned side-effect: "Note: any StreamableEventSource implementation that currently branches on condition.position() == null (instead of also checking TrackingToken.FIRST) will stop seeing null after this change and needs a matching update."
is unclear to me ... who will hit this?
approving and leaving the record vs class to your judgment
See PR AxonIQ/axoniq-framework#542 -- axoniq hits it there, as some code was already doing
|
StartingFrom accepted a null position as a legacy synonym for "start from the beginning", while TrackingToken.FIRST exists specifically to express that explicitly. Having two spellings of the same request meant consumers only had to handle one of them correctly to look right in tests, while the other silently broke depending on the implementation (type-check exceptions, wrong resolved sequence, etc).
Note: any StreamableEventSource implementation that currently branches on
condition.position() == null(instead of also checkingTrackingToken.FIRST) will stop seeing null after this change and needs a matching update.