Conversation
…15) - Drop Objects.requireNonNull from request-DTO canonical constructors (Crecust, Creacc, Dbcrfun, Updcust, Delcus and their nested Commarea/Key DTOs) so missing fields surface as 400 from MethodArgumentNotValidException instead of 500/UNEX from a Jackson NPE escape (issue #15). - Tighten CrecustCommareaRequestDto.commName / UpdcustCommareaRequestDto .commName/commAddress with @notblank and remove the bypass empty string from CrecustService.VALID_TITLES so blank/whitespace names cannot pass title validation (issue #10). - Add WebMvc tests covering missing-required-field and blank-name paths, and a CrecustService unit test for the empty-name rejection. - Document the rule in docs/translation-rules.md \xc2\xa76.
Contributor
|
✅ Test coverage looks good. The new/changed behavior in this PR has adequate test coverage. No additional tests needed. The PR refactors validation from
All critical validation paths are exercised. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10, closes #15.
Why
Two related polish items:
CREACC DTOs: replace
Objects.requireNonNullin record constructors with bean-validation so missing fields return 400, not 500 #15 —Objects.requireNonNull(...)calls inside the canonicalconstructor of a request-DTO record are executed by Jackson during
deserialization. When a required field is missing from the JSON body,
Jackson sees a null component, the constructor throws
NullPointerException, andCbsaExceptionHandler#handleUnexpectedsurfaces it as a
500with abend codeUNEXinstead of the intended400 Validation failed. Bean-validation annotations on thecomponents, combined with
@Validon the controller parameter andevery nested DTO/Key reference, give us the proper 400.
CRECUST: tighten CommName validation (no blank/whitespace via empty title) #10 —
VALID_TITLESinCrecustServicecontained an emptystring, which let an empty/whitespace-only
CommNamesilently bypasstitle validation. Tighten by (a) requiring
@NotBlankat the wireboundary on
CrecustCommareaRequestDto.commNameand onUpdcustCommareaRequestDto.commName/commAddress, and (b) removingthe empty-string entry from
VALID_TITLESso the service-layer guardalso rejects blank names with fail code
T.What
Objects.requireNonNullfrom the canonical constructor of everyrequest DTO and nested Commarea/Key DTO that participates in JSON
deserialization:
CrecustRequestDto,CrecustCommareaRequestDto,CrecustKeyDto,CreaccRequestDto,CreaccCommareaRequestDto,CreaccKeyDto,DbcrfunRequestDto,UpdcustRequestDto,UpdcustCommareaRequestDto,DelcusRequestDto. Existing@NotNull/
@Validannotations carry the contract.@NotBlankonCrecustCommareaRequestDto.commNameand onUpdcustCommareaRequestDto.commName/commAddress.CrecustService.VALID_TITLESsothe service-layer fallback also rejects blank names.
docs/translation-rules.md §6so future programtranslations follow the same pattern.
Tests
CrecustControllerWebMvcTest:missingRequiredFieldReturnsBadRequest— omittingCommNameyields
400(previously would have been500/UNEX).blankCommNameReturnsBadRequest— whitespace-onlyCommNameyields
400via@NotBlank.CrecustServiceUnitTest:rejectsBlankCustomerNamesAtTitleValidation— locks in theservice-layer rejection of blank names with fail code
T../mvnw verify: 205/205 green locally.augment review