Skip to content

Fix unhandled DateTimeParseException on malformed date query params#56

Merged
lukepring merged 3 commits intoSprint-2-Jackfrom
copilot/sub-pr-55
Mar 20, 2026
Merged

Fix unhandled DateTimeParseException on malformed date query params#56
lukepring merged 3 commits intoSprint-2-Jackfrom
copilot/sub-pr-55

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

Malformed startDate/endDate query params (e.g. /compare?startDate=not-a-date) caused an unhandled DateTimeParseException, surfacing as a 500.

Changes

  • Parameter types: Replaced String + manual LocalDate.parse() with @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate — Spring MVC owns parsing, invalid input is caught at binding time instead of mid-method.
  • Error handling: Added @ExceptionHandler(MethodArgumentTypeMismatchException.class) that returns a user-facing message on the index page naming the offending param, with form defaults repopulated.
// Before — throws unhandled DateTimeParseException on bad input
@RequestParam(required = false) String startDate,
LocalDate start = (startDate != null && !startDate.isBlank()) ? LocalDate.parse(startDate) : ...;

// After — Spring handles parsing; type mismatch caught by @ExceptionHandler
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
LocalDate start = (startDate != null) ? startDate : LocalDate.now().minusYears(1);

The exception handler distinguishes date params from other type mismatches, returning e.g. "Invalid date format for 'startDate'. Please use YYYY-MM-DD (e.g. 2024-01-15)." rather than a generic or HTTP error response.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: lukepring <68820847+lukepring@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback from review on Sprint 2 jack pull request Fix unhandled DateTimeParseException on malformed date query params Mar 20, 2026
Copilot AI requested a review from lukepring March 20, 2026 15:55
@lukepring lukepring marked this pull request as ready for review March 20, 2026 16:20
@lukepring
Copy link
Copy Markdown
Owner

@copilot check the merge conflict ty x

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 20, 2026

@copilot check the merge conflict ty x

Checked against base Sprint-2-Jack; branch merges cleanly with no conflicts (no new commit required).

@lukepring lukepring merged commit 6f66f31 into Sprint-2-Jack Mar 20, 2026
1 check passed
@lukepring lukepring deleted the copilot/sub-pr-55 branch March 20, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants