Skip to content

Conversation

@arturobernalg
Copy link
Member

Fixes overflow handling in Deadline calculation to ensure proper behavior when adding large time values, returning Deadline.MAX_VALUE in case of overflow.

if (TimeValue.isPositive(timeValue)) {
// TODO handle unlikely overflow
final long deadline = timeMillis + timeValue.toMilliseconds();
final long timeToAdd = timeValue.toMilliseconds();
Copy link
Member

@ok2c ok2c Jan 10, 2025

Choose a reason for hiding this comment

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

@arturobernalg Should not this do the same, just with a bit less code? I also think timeToAdd > 0 and deadline < 0 are unnecessary.

        if (TimeValue.isPositive(timeValue)) {
            return Deadline.fromUnixMilliseconds(timeMillis +
                    Math.min(timeValue.toMilliseconds(), Long.MAX_VALUE - timeMillis));
        }
        return Deadline.MAX_VALUE;

Copy link
Member Author

Choose a reason for hiding this comment

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

@ok2c Updated the implementation as suggested. Thanks for the feedback!

@arturobernalg arturobernalg merged commit fd5c617 into apache:master Jan 10, 2025
10 checks passed
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.

2 participants