[threeten-dev] Instant.with(TemporalField, long) does not throw ArithmeticException for numeric overflow error

Patrick Zhang patrick.zhang at oracle.com
Sun Feb 17 07:27:04 PST 2013


Hi Team,

I have found such a problem during creating new test code for 
java.time.Instant.
It can be reproduced easily by below:

                 Instant i1 = Instant.ofEpochSecond(1, -10) ;
                 Instant i3 = i1.with(ChronoField.NANO_OF_SECOND, 
1000000000L);

As javadoc description, it should throw ArithmeticException since range 
of NANO_OF_SECOND is 0-999999999.

Actually it throws DateTimeException,
=======
Exception in thread "main" java.time.DateTimeException: Invalid value 
for NanoOfSecond (valid values 0 - 999999999): 1000000000
     at java.time.temporal.ValueRange.checkValidValue(ValueRange.java:309)
     at java.time.temporal.ChronoField.checkValidValue(ChronoField.java:583)
     at java.time.Instant.with(Instant.java:632)
     at Test1.f1(Test1.java:14)
     at Test1.main(Test1.java:5)
=======

Regards
Patrick


More information about the threeten-dev mailing list