Skip to content

[FLINK-34022][core] Fix ArithmeticException in TimeUtils.formatWithHighestUnit for large Duration values#27877

Open
balassai wants to merge 1 commit intoapache:release-1.20from
balassai:backport-FLINK-34022-release-1.20
Open

[FLINK-34022][core] Fix ArithmeticException in TimeUtils.formatWithHighestUnit for large Duration values#27877
balassai wants to merge 1 commit intoapache:release-1.20from
balassai:backport-FLINK-34022-release-1.20

Conversation

@balassai
Copy link
Copy Markdown
Contributor

@balassai balassai commented Apr 1, 2026

What is the purpose of the change

Backport of FLINK-35820 to release-1.20.

TimeUtils.formatWithHighestUnit() internally called Duration.toNanos() which throws an ArithmeticException when the nanosecond value overflows a long (e.g. Duration.ofMillis(Long.MAX_VALUE)).

Brief change log

  • Convert internal nanosecond computation from long to BigInteger to avoid arithmetic overflow
  • Add test cases in TimeUtilsPrettyPrintingTest covering Long.MAX_VALUE ms and values beyond long range

Verifying this change

  • New parameterized test cases added to TimeUtilsPrettyPrintingTest

…nit for large Duration values

Duration.toNanos() throws ArithmeticException when the nanosecond value
overflows a long (e.g. Duration.ofMillis(Long.MAX_VALUE)).

Fix by converting the internal computation to BigInteger throughout
formatWithHighestUnit, toNanos, and getHighestIntegerUnit, matching
the fix already applied to main via FLINK-35820.
@flinkbot
Copy link
Copy Markdown
Collaborator

flinkbot commented Apr 1, 2026

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants