Skip to content

[Coral-Data-Generation] Keep IntegerDomain samples inside intervals wider than Long.MAX_VALUE - #629

Open
sebxt wants to merge 1 commit into
linkedin:masterfrom
sebxt:fix/integer-domain-sample-wide-interval
Open

sebxt wants to merge 1 commit into
linkedin:masterfrom
sebxt:fix/integer-domain-sample-wide-interval

Conversation

@sebxt

@sebxt sebxt commented Oct 20, 2026

Copy link
Copy Markdown

What changes are proposed in this pull request, and why are they necessary?

IntegerDomain.sampleFromInterval has an overflow branch for intervals whose width exceeds Long.MAX_VALUE, but it still computes interval.max - interval.min as a long. The difference wraps around, so:

  • IntegerDomain.of(Long.MIN_VALUE, 5).sample(n) returns large positive values that are not in the domain.
  • IntegerDomain.all().sample(n) always returns Long.MIN_VALUE.

This change computes the width in double, samples in double space, and clamps the result to [min, max] to absorb rounding at the edges.

How was this patch tested?

Added IntegerDomainTest.testSampleIntervalWiderThanLongMaxValue, which samples [Long.MIN_VALUE, 5], [-5, Long.MAX_VALUE] and IntegerDomain.all(), and checks that every sample is contained in the domain and that the samples are not all the same value. It fails on master (IntegerDomain[[-9223372036854775808, 5]] sampled 8059531451386583040) and passes with the fix; I ran it repeatedly to make sure it is not flaky.

./gradlew :coral-data-generation:spotlessCheck :coral-data-generation:test passes.

Fixes #628

…ider than Long.MAX_VALUE

Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
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.

IntegerDomain.sample returns values outside the domain for intervals wider than Long.MAX_VALUE

1 participant