Details
Description
A DESCRIPTION OF THE PROBLEM :
When the distance between two instants is larger that Long.MAX_VALUE nanos, but less than Long.MAX_VALUE micros, ChronoUnit.MICROS.between() fails. This is due to the computation performed, which in OpenJDK 11 is in java.time.Instant, line 1148: nanosUntil(end) / 1000. nanosUntil overflows and throws an arithmetic exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Instant gregorianEpoch = Instant.EPOCH.minusSeconds(12219292800l);
Instant now = Instant.now();
long micros = ChronoUnit.MICROS.between(gregorianEpoch, now); -> Math.addExact throws ArithmeticException
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Correct long value returned
ACTUAL -
ArithmeticException
FREQUENCY : always
When the distance between two instants is larger that Long.MAX_VALUE nanos, but less than Long.MAX_VALUE micros, ChronoUnit.MICROS.between() fails. This is due to the computation performed, which in OpenJDK 11 is in java.time.Instant, line 1148: nanosUntil(end) / 1000. nanosUntil overflows and throws an arithmetic exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Instant gregorianEpoch = Instant.EPOCH.minusSeconds(12219292800l);
Instant now = Instant.now();
long micros = ChronoUnit.MICROS.between(gregorianEpoch, now); -> Math.addExact throws ArithmeticException
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Correct long value returned
ACTUAL -
ArithmeticException
FREQUENCY : always