Java

Java

Made by DeepSource

Invalid values for java.time constants will always throw a DateTimeException JAVA-E1099

Bug risk
Critical

Calling any method of the java.time package with invalid constant values will throw a DateTimeException.

Bad Practice

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.

Recommended

Use values within the valid range for the specific date/time field when calling such methods.

LocalDate date = LocalDate.of(1985, Month.MAY, 31);