Skip to content

polish(validation): replace requireNonNull with bean validation (#10, #15)#44

Merged
a2chang merged 1 commit intomainfrom
polish/issues-15-10-bean-validation
May 1, 2026
Merged

polish(validation): replace requireNonNull with bean validation (#10, #15)#44
a2chang merged 1 commit intomainfrom
polish/issues-15-10-bean-validation

Conversation

@a2chang
Copy link
Copy Markdown
Contributor

@a2chang a2chang commented May 1, 2026

Closes #10, closes #15.

Why

Two related polish items:

  • CREACC DTOs: replace Objects.requireNonNull in record constructors with bean-validation so missing fields return 400, not 500 #15Objects.requireNonNull(...) calls inside the canonical
    constructor 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, and CbsaExceptionHandler#handleUnexpected
    surfaces it as a 500 with abend code UNEX instead of the intended
    400 Validation failed. Bean-validation annotations on the
    components, combined with @Valid on the controller parameter and
    every nested DTO/Key reference, give us the proper 400.

  • CRECUST: tighten CommName validation (no blank/whitespace via empty title) #10VALID_TITLES in CrecustService contained an empty
    string, which let an empty/whitespace-only CommName silently bypass
    title validation. Tighten by (a) requiring @NotBlank at the wire
    boundary on CrecustCommareaRequestDto.commName and on
    UpdcustCommareaRequestDto.commName/commAddress, and (b) removing
    the empty-string entry from VALID_TITLES so the service-layer guard
    also rejects blank names with fail code T.

What

  • Drop Objects.requireNonNull from the canonical constructor of every
    request DTO and nested Commarea/Key DTO that participates in JSON
    deserialization: CrecustRequestDto, CrecustCommareaRequestDto,
    CrecustKeyDto, CreaccRequestDto, CreaccCommareaRequestDto,
    CreaccKeyDto, DbcrfunRequestDto, UpdcustRequestDto,
    UpdcustCommareaRequestDto, DelcusRequestDto. Existing @NotNull
    / @Valid annotations carry the contract.
  • Add @NotBlank on CrecustCommareaRequestDto.commName and on
    UpdcustCommareaRequestDto.commName/commAddress.
  • Remove the empty-string entry from CrecustService.VALID_TITLES so
    the service-layer fallback also rejects blank names.
  • Document the rule in docs/translation-rules.md §6 so future program
    translations follow the same pattern.

Tests

  • CrecustControllerWebMvcTest:
    • missingRequiredFieldReturnsBadRequest — omitting CommName
      yields 400 (previously would have been 500/UNEX).
    • blankCommNameReturnsBadRequest — whitespace-only CommName
      yields 400 via @NotBlank.
  • CrecustServiceUnitTest:
    • rejectsBlankCustomerNamesAtTitleValidation — locks in the
      service-layer rejection of blank names with fail code T.

./mvnw verify: 205/205 green locally.

augment review

…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.
@augmentcode
Copy link
Copy Markdown
Contributor

augmentcode Bot commented May 1, 2026

Test Coverage Guardian 🧪

Test coverage looks good. The new/changed behavior in this PR has adequate test coverage. No additional tests needed.

The PR refactors validation from Objects.requireNonNull to bean validation annotations and includes three focused tests:

All critical validation paths are exercised.

Copy link
Copy Markdown

@augment-app-staging augment-app-staging Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@a2chang a2chang merged commit b5741bf into main May 1, 2026
1 check passed
@a2chang a2chang deleted the polish/issues-15-10-bean-validation branch May 1, 2026 22:00
@a2chang a2chang mentioned this pull request May 1, 2026
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant