Why this matters
Input dates are error-prone; explicit handling prevents runtime crashes.
Parse dates with DateTimeFormatter in try/catch and validate expected formats/timezones.
Input dates are error-prone; explicit handling prevents runtime crashes.
Side-by-side examples engineers can pattern-match during review.
LocalDate.parse(s);try {
var d = LocalDate.parse(s, DateTimeFormatter.ISO_LOCAL_DATE);
} catch (DateTimeParseException e) {
return badRequest("invalid date");
}ZonedDateTime.parse(s)try { parse } catch(DateTimeParseException e) { /* handle */ }From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.