Merge "Fix NPE in ChangeDetailFactory for loadMessages isPatchVisible"
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeDetailFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeDetailFactory.java
index 36c9ff1..cf8b4db 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeDetailFactory.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeDetailFactory.java
@@ -214,7 +214,7 @@
       PatchSet.Id id = msg.getPatchSetId();
       if (id != null) {
         PatchSet ps = patchsetsById.get(msg.getPatchSetId());
-        if (control.isPatchVisible(ps, db)) {
+        if (ps != null && control.isPatchVisible(ps, db)) {
           msgList.add(msg);
         }
       } else {