Skip to content

FINERACT-2511: Validate dateFormat parameter to return HTTP 400 instead of 500 - #5596

Merged
adamsaghy merged 1 commit into
apache:developfrom
Harshitmehra-270709:fix/FINERACT-2511-validate-dateFormat
Mar 16, 2026
Merged

FINERACT-2511: Validate dateFormat parameter to return HTTP 400 instead of 500#5596
adamsaghy merged 1 commit into
apache:developfrom
Harshitmehra-270709:fix/FINERACT-2511-validate-dateFormat

Conversation

@Harshitmehra-270709

Copy link
Copy Markdown
Contributor

Description

Fixes FINERACT-2511: Invalid dateFormat on client create returns HTTP 500 instead of 400 Bad Request.

Root Cause

When an invalid dateFormat value (e.g., 02 February 2026 instead of a valid pattern like dd MMMM yyyy) is provided in POST /fineract-provider/api/v1/clients, ClientDataValidator.validateForCreate() does not validate this parameter. The invalid value reaches DateTimeFormatter.ofPattern(command.dateFormat()) in ClientWritePlatformServiceJpaRepositoryImpl.createClient(), which throws IllegalArgumentException. This uncaught exception surfaces as HTTP 500.

Changes

  1. DataValidatorBuilder.java - Added a reusable validDateTimeFormatPattern() method that validates date/time format pattern strings by attempting DateTimeFormatter.ofPattern() and catching IllegalArgumentException. This method follows the existing fluent API pattern and can be reused by other validators across the codebase.

  2. ClientDataValidator.java - Added dateFormat validation in both validateForCreate() and validateForUpdate() using the new validDateTimeFormatPattern() method. Invalid patterns are now caught during validation and returned as HTTP 400 with a clear error message.

  3. DataValidatorBuilderDateFormatTest.java [NEW] - 12 parameterized unit tests covering:

    • Valid patterns (dd MMMM yyyy, yyyy-MM-dd, dd/MM/yyyy, MM/dd/yyyy, dd-MM-yyyy HH:mm:ss)
    • Invalid patterns (02 February 2026, not-a-pattern, P!@#$, {{invalid}})
    • Null value handling (with and without ignoreIfNull)
    • Blank value handling

Testing

  • All 12 unit tests pass (0 failures, 0 errors)
  • fineract-core:compileJava BUILD SUCCESSFUL
  • Code formatted via spotlessJavaApply

@adamsaghy

Copy link
Copy Markdown
Contributor

@Harshitmehra-270709 Please rebase this PR with latest develop branch.
Please make sure you have a configured GPG signature and valid email address.

…ad of 500

When an invalid dateFormat (e.g., a date value like '02 February 2026' instead of a pattern like 'dd MMMM yyyy') is provided during client creation, DateTimeFormatter.ofPattern() throws an IllegalArgumentException that surfaces as HTTP 500.

This commit:

- Adds a reusable validDateTimeFormatPattern() method to DataValidatorBuilder that validates date/time format patterns by attempting DateTimeFormatter.ofPattern() and catching IllegalArgumentException

- Adds dateFormat validation in ClientDataValidator.validateForCreate() and validateForUpdate() using the new method

- Adds DataValidatorBuilderDateFormatTest with 12 parameterized unit tests covering valid patterns, invalid patterns, null, and blank edge cases
@Harshitmehra-270709
Harshitmehra-270709 force-pushed the fix/FINERACT-2511-validate-dateFormat branch from e26d863 to adee68f Compare March 10, 2026 18:37
@Harshitmehra-270709

Copy link
Copy Markdown
Contributor Author

@Harshitmehra-270709 Please rebase this PR with latest develop branch. Please make sure you have a configured GPG signature and valid email address.

Yes, sir, I did all the changes, and I have a question: Where do all the contributors and maintainers hang out?
or discuss things?

@adamsaghy

Copy link
Copy Markdown
Contributor

@Harshitmehra-270709 Please rebase this PR with latest develop branch. Please make sure you have a configured GPG signature and valid email address.

Yes, sir, I did all the changes, and I have a question: Where do all the contributors and maintainers hang out? or discuss things?

Official dev mail list:
https://fineract.apache.org -> Mailing list

Unofficial slack channel:
"Mifos" as the organization and look for "fineract" channel.

@adamsaghy
adamsaghy merged commit 9da7e3a into apache:develop Mar 16, 2026
83 checks passed
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