"todo-mvp-rxjava" Possible to create empty task
When trying to create a task without name Snackbar appears and save not happening. But if you create a task, and then try to edit, put there an empty name, then the task is being saved with an empty name.
the bug is essentially:
Add flow → validation works: if you try to create a new task with an empty title, the Snackbar warns you and the task isn’t saved.
Edit flow → validation missing: if you open an existing task, delete the title, and save, it does save with an empty title.
Why this happens in todo-mvp-rxjava In the RxJava branch:
AddEditTaskPresenter (or ViewModel equivalent) has validation logic in the add path:
if (title.isEmpty()) { mAddTaskView.showEmptyTaskError(); } else { mTasksRepository.saveTask(new Task(title, description)); } But in the edit path, it’s doing something like:
Task task = mTask; // existing task.setTitle(title); task.setDescription(description); mTasksRepository.saveTask(task); …without checking if the new title is empty.
How to fix it We just need the same validation for edits as for adds.
Before
private void saveTask(String title, String description) { if (mIsNewTask) { createTask(title, description); } else { updateTask(title, description); } } After
private void saveTask(String title, String description) { if (title == null || title.trim().isEmpty()) { mAddTaskView.showEmptyTaskError(); return; }
if (mIsNewTask) {
createTask(title, description);
} else {
updateTask(title, description);
}
} This way both create and update paths are blocked if the title is empty.
Why it’s important Keeps data integrity consistent — you can’t bypass validation just by editing.
Matches the user experience between Add and Edit flows.
Prevents persisting invalid tasks that might cause issues elsewhere in the app.