Skip to content

The Unified and Autonomous Development Platform

fix: Issue comment: Exception on user autocomplete if issue creator is a deleted user (OD-2058)

Robin Shenb8ce8e3e8bc1
diff --git a/server-core/src/main/java/io/onedev/server/model/CodeComment.java b/server-core/src/main/java/io/onedev/server/model/CodeComment.java
index 94c181d767..d5bfadc97a 100644
--- a/server-core/src/main/java/io/onedev/server/model/CodeComment.java
+++ b/server-core/src/main/java/io/onedev/server/model/CodeComment.java
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.onedev.server.OneDev;
import io.onedev.server.attachment.AttachmentStorageSupport;
+import io.onedev.server.entitymanager.UserManager;
import io.onedev.server.git.service.GitService;
import io.onedev.server.model.support.CompareContext;
import io.onedev.server.model.support.LastActivity;
@@ -279,12 +280,12 @@ public class CodeComment extends ProjectBelonging implements AttachmentStorageSu
public List<User> getParticipants() {
if (participants == null) {
participants = new LinkedHashSet<>();
- if (getUser() != null)
- participants.add(getUser());
- for (CodeCommentReply reply: getReplies()) {
- if (reply.getUser() != null)
- participants.add(reply.getUser());
- }
+ participants.add(getUser());
+ for (CodeCommentReply reply: getReplies())
+ participants.add(reply.getUser());
+ var userManager = OneDev.getInstance(UserManager.class);
+ participants.remove(userManager.getSystem());
+ participants.remove(userManager.getUnknown());
}
return new ArrayList<>(participants);
}
diff --git a/server-core/src/main/java/io/onedev/server/model/Issue.java b/server-core/src/main/java/io/onedev/server/model/Issue.java
index 26b6800c66..e2711c482e 100644
--- a/server-core/src/main/java/io/onedev/server/model/Issue.java
+++ b/server-core/src/main/java/io/onedev/server/model/Issue.java
@@ -815,8 +815,7 @@ public class Issue extends ProjectBelonging implements AttachmentStorageSupport
public List<User> getParticipants() {
if (participants == null) {
participants = new LinkedHashSet<>();
- if (getSubmitter() != null)
- participants.add(getSubmitter());
+ participants.add(getSubmitter());
UserManager userManager = OneDev.getInstance(UserManager.class);
for (IssueField field: getFields()) {
if (field.getType().equals(InputSpec.USER)) {
@@ -833,15 +832,14 @@ public class Issue extends ProjectBelonging implements AttachmentStorageSupport
}
}
}
- for (IssueComment comment: getComments()) {
- if (comment.getUser() != null)
- participants.add(comment.getUser());
- }
+ for (IssueComment comment: getComments())
+ participants.add(comment.getUser());
for (IssueChange change: getChanges()) {
if (change.getUser() != null)
participants.add(change.getUser());
}
participants.remove(userManager.getSystem());
+ participants.remove(userManager.getUnknown());
}
return new ArrayList<>(participants);
}
diff --git a/server-core/src/main/java/io/onedev/server/model/PullRequest.java b/server-core/src/main/java/io/onedev/server/model/PullRequest.java
index ad22d11bf6..80159ce0aa 100644
--- a/server-core/src/main/java/io/onedev/server/model/PullRequest.java
+++ b/server-core/src/main/java/io/onedev/server/model/PullRequest.java
@@ -851,17 +851,16 @@ public class PullRequest extends ProjectBelonging
public List<User> getParticipants() {
if (participants == null) {
participants = new LinkedHashSet<>();
- if (getSubmitter() != null)
- participants.add(getSubmitter());
- for (PullRequestComment comment: getComments()) {
- if (comment.getUser() != null)
- participants.add(comment.getUser());
- }
+ participants.add(getSubmitter());
+ for (PullRequestComment comment: getComments())
+ participants.add(comment.getUser());
for (PullRequestChange change: getChanges()) {
if (change.getUser() != null)
participants.add(change.getUser());
}
- participants.remove(OneDev.getInstance(UserManager.class).getSystem());
+ var userManager = OneDev.getInstance(UserManager.class);
+ participants.remove(userManager.getSystem());
+ participants.remove(userManager.getUnknown());
}
return new ArrayList<>(participants);
}