Skip to content

Commit

Permalink
fixed a possible NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Apr 3, 2020
1 parent a7bef9b commit de7b656
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,17 @@ public String reply(@PathVariable String id, @PathVariable(required = false) Str
HttpServletResponse res, Model model) {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (showPost != null && emailme != null) {
if (emailme) {
showPost.addFollower(authUser.getUser());
if (authUser == null || showPost == null) {
if (utils.isAjaxRequest(req)) {
res.setStatus(400);
return "base";
} else {
showPost.removeFollower(authUser.getUser());
return "redirect:" + QUESTIONSLINK + "/" + id;
}
pc.update(showPost); // update without adding revisions
} else if (showPost != null && !showPost.isClosed() && !showPost.isReply()) {
}
if (emailme != null) {
followPost(showPost, authUser, emailme);
} else if (!showPost.isClosed() && !showPost.isReply()) {
//create new answer
boolean needsApproval = utils.postNeedsApproval(authUser);
Reply answer = utils.populate(req, needsApproval ? new UnapprovedReply() : new Reply(), "body");
Expand Down Expand Up @@ -433,4 +436,13 @@ private Object getAcceptedAnswerPayload(Post showPost, Reply answer, Profile aut
payload.put("authUser", authUser);
return payload;
}

private void followPost(Post showPost, Profile authUser, Boolean emailme) {
if (emailme) {
showPost.addFollower(authUser.getUser());
} else {
showPost.removeFollower(authUser.getUser());
}
pc.update(showPost); // update without adding revisions
}
}

0 comments on commit de7b656

Please sign in to comment.