Skip to content

Normalize null position to TrackingToken.FIRST in StartingFrom - #5086

Open
hjohn wants to merge 1 commit into
mainfrom
startingfrom-normalize-null-to-first
Open

hjohn wants to merge 1 commit into
mainfrom
startingfrom-normalize-null-to-first

Conversation

@hjohn

@hjohn hjohn commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

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).

  • Normalize null to TrackingToken.FIRST in StartingFrom's constructor, so position() never returns null and there's exactly one way to express "start from the beginning" going forward.
  • Explicitly override position() so the accessor doesn't inherit the @nullable annotation from the record component (which only exists to let the constructor accept null input).
  • Drop the now-unreachable null-position exceptions in withCriteria/or.
  • Simplify the matching null-position branch in the AsyncInMemoryStreamableEventSource test fixture.

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.

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.
@hjohn
hjohn force-pushed the startingfrom-normalize-null-to-first branch from 1afc0d7 to c8f3f0e Compare September 28, 2026 11:53
@hjohn hjohn self-assigned this Sep 28, 2026
@hjohn hjohn added Type: Bug Use to signal issues that describe a bug within the system. Priority 3: Could Low priority. Issues that are nice to have but have a straightforward workaround. labels Sep 28, 2026
@hjohn hjohn added this to the Release 5.4.0 milestone Sep 28, 2026
@hjohn
hjohn marked this pull request as ready for review September 28, 2026 11:57
@hjohn
hjohn requested a review from a team as a code owner September 28, 2026 11:57
@hjohn
hjohn requested review from MateuszNaKodach, jangalinski and zambrovski and removed request for a team September 28, 2026 11:57
* @author Steven van Beelen
* @since 5.0.0
*/
record StartingFrom(@Nullable TrackingToken position) implements StreamingCondition {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;
    }
   ....
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It could indeed be a class to make this more clear, I think that would be backwards compatible, but I have to check.

@jangalinski jangalinski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@hjohn

hjohn commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

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?

See PR AxonIQ/axoniq-framework#542 -- axoniq hits it there, as some code was already doing null to first token translation themselves, even though the interface says null wasn't allowed.

approving and leaving the record vs class to your judgment

@smcvb smcvb modified the milestones: Release 5.4.0, Release 5.5.0 Oct 1, 2026
@smcvb smcvb added Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. and removed Priority 3: Could Low priority. Issues that are nice to have but have a straightforward workaround. labels Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority 2: Should High priority. Ideally, these issues are part of the release they’re assigned to. Type: Bug Use to signal issues that describe a bug within the system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants