java.time
constants will always throw a DateTimeException
JAVA-E1099Calling any method of the java.time
package with invalid constant values will throw a DateTimeException
.
LocalDate date = LocalDate.of(1985, Month.MAY, 32);
In the code above, the LocalDate
object is instantiated with a day-of-month value of 32
, which is a plainly invalid day of any month. This will result in a DateTimeException
at runtime.
Use values within the valid range for the specific date/time field when calling such methods.
LocalDate date = LocalDate.of(1985, Month.MAY, 31);