You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PR moves TaskStatus into a proper enum and changes the status endpoint to a 204 No Content response, which is a good direction. However, there are several issues that should be fixed before merging.
1. @NotBlank is invalid on an enum field
@NotBlank is only valid for CharSequence fields (String, StringBuilder, etc.). Applying it to an enum will cause a UnexpectedTypeException if Bean Validation is triggered for that object.
ChangeStatusRequest has validation annotations (@NotBlank, @Size), but they will not be triggered unless the controller parameter is annotated with @Valid (or @Validated).
3. TaskStatus.valueOf(...) in the controller can cause a 500
If the client sends an invalid status string, TaskStatus.valueOf throws IllegalArgumentException, which by default returns 500 Internal Server Error. That should be a 400 Bad Request.
A cleaner approach is to use TaskStatus directly in the request DTO, so Jackson handles invalid values with a 400.
4. Business rule violation throws IllegalArgumentException
validateChangeStatus throws IllegalArgumentException when an invalid transition occurs. This will also produce a 500 Internal Server Error. A status transition violation is a client error, so it should map to 400 or 409.
Suggested change: introduce a domain exception.
publicclassInvalidTaskStatusTransitionExceptionextendsRuntimeException {
publicInvalidTaskStatusTransitionException(TaskStatusoldStatus, TaskStatusnewStatus) {
super(String.format("Cannot change task status from %s to %s", oldStatus, newStatus));
}
}
The check newStatus.ordinal() < oldStatus.ordinal() is fragile. Reordering enum constants will silently change business rules. It also makes the allowed transitions hard to reason about, especially the special BLOCKED case.
A clearer approach is to define an explicit transition map:
This makes the workflow explicit and independent of enum declaration order.
6. Same-status transition still saves, updates updatedAt, and publishes an event
Currently if oldStatus equals newStatus, validateChangeStatus returns early, but handle still continues to updateTask and publishes a TaskStatusChangedEvent. This will overwrite updatedAt and emit a no-op event.
If same-status changes should be idempotent, return early:
Also update the controller test to verify invalid status strings return 400, if you keep the String DTO approach.
Summary
The main blockers are:
@NotBlank on enum — use @NotNull
Missing @Valid on request body
IllegalArgumentException for invalid transitions maps to 500
Log message mistake in CreateTaskServiceImpl
The larger design issue is the ordinal-based transition validation. Replacing it with an explicit map will make the state machine clear and safe.
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
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.
No description provided.