FINERACT-2511: Validate dateFormat parameter to return HTTP 400 instead of 500#5596
Conversation
|
@Harshitmehra-270709 Please rebase this PR with latest |
…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
e26d863 to
adee68f
Compare
Yes, sir, I did all the changes, and I have a question: Where do all the contributors and maintainers hang out? |
Official dev mail list: Unofficial slack channel: |
Description
Fixes FINERACT-2511: Invalid
dateFormaton client create returns HTTP 500 instead of 400 Bad Request.Root Cause
When an invalid
dateFormatvalue (e.g.,02 February 2026instead of a valid pattern likedd MMMM yyyy) is provided inPOST /fineract-provider/api/v1/clients,ClientDataValidator.validateForCreate()does not validate this parameter. The invalid value reachesDateTimeFormatter.ofPattern(command.dateFormat())inClientWritePlatformServiceJpaRepositoryImpl.createClient(), which throwsIllegalArgumentException. This uncaught exception surfaces as HTTP 500.Changes
DataValidatorBuilder.java- Added a reusablevalidDateTimeFormatPattern()method that validates date/time format pattern strings by attemptingDateTimeFormatter.ofPattern()and catchingIllegalArgumentException. This method follows the existing fluent API pattern and can be reused by other validators across the codebase.ClientDataValidator.java- AddeddateFormatvalidation in bothvalidateForCreate()andvalidateForUpdate()using the newvalidDateTimeFormatPattern()method. Invalid patterns are now caught during validation and returned as HTTP 400 with a clear error message.DataValidatorBuilderDateFormatTest.java[NEW] - 12 parameterized unit tests covering:dd MMMM yyyy,yyyy-MM-dd,dd/MM/yyyy,MM/dd/yyyy,dd-MM-yyyy HH:mm:ss)02 February 2026,not-a-pattern,P!@#$,{{invalid}})ignoreIfNull)Testing
fineract-core:compileJavaBUILD SUCCESSFULspotlessJavaApply