Skip to content

Commit

Permalink
Fix an NPE when task does not exist (#880)
Browse files Browse the repository at this point in the history
Handle the case when `taskScheduler.getTaskForUser` returns `null` so that we to prevent `NullPointerException`s.
  • Loading branch information
trevorgerhardt authored May 30, 2023
1 parent 05aa44e commit dbcc567
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ private Object removeActivity (Request req, Response res) {
UserPermissions userPermissions = UserPermissions.from(req);
String id = req.params("id");
Task task = taskScheduler.getTaskForUser(userPermissions.email, id);
// Check if task still exists before attempting to remove.
if (task == null) {
throw AnalysisServerException.notFound("Task does not exist. It may have already been removed by another user.");
}
// Disallow removing active tasks via the API.
if (task.state.equals(Task.State.ACTIVE)) {
throw AnalysisServerException.badRequest("Cannot clear an active task.");
Expand Down

0 comments on commit dbcc567

Please sign in to comment.