[threeten-dev] Instant.with(TemporalField, long) does not throw ArithmeticException for numeric overflow error
    Stephen Colebourne 
    scolebourne at joda.org
       
    Sun Feb 17 13:46:33 PST 2013
    
    
  
On 17 February 2013 15:27, Patrick Zhang <patrick.zhang at oracle.com> wrote:
> 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)
> =======
DateTimeException is the correct error here.
ArithmeticException is for numeric overflow, such as multiplying two
numbers exceeds the capability of an int.
DateTimeException includes general argument validity problems, like that above.
Stephen
    
    
More information about the threeten-dev
mailing list