Adjust comment range if endLine < startLine
It looks like there are some cases when comments, created in reply to
robot comments can have endLine=0, which results in an exception
here[1], failing the entire /changes/~/comments endpoint results.
It would be nice to chase those cases down, but as a temporary fix,
adjust the range so that it does not result in an exception
[1]https://gerrit.googlesource.com/gerrit/+/b5b76c0/java/com/google/gerrit/server/comment/CommentContextLoader.java#209
Change-Id: I6627f5c68e98520d72c16cdbe5bc3704822060fc
Release-Notes: skip
Google-Bug-Id: b/266469968
diff --git a/java/com/google/gerrit/server/comment/CommentContextLoader.java b/java/com/google/gerrit/server/comment/CommentContextLoader.java
index 8fbb259..0df7729 100644
--- a/java/com/google/gerrit/server/comment/CommentContextLoader.java
+++ b/java/com/google/gerrit/server/comment/CommentContextLoader.java
@@ -225,6 +225,11 @@
private static Optional<Range> getStartAndEndLines(ContextInput comment) {
if (comment.range() != null) {
+ if (comment.range().endLine < comment.range().startLine) {
+ // Seems like comments, created in reply to robot comments sometimes have invalid ranges
+ // Fix here, otherwise the range is invalid and we throw an error later on.
+ return Optional.of(Range.create(comment.range().startLine, comment.range().startLine + 1));
+ }
return Optional.of(Range.create(comment.range().startLine, comment.range().endLine + 1));
} else if (comment.lineNumber() > 0) {
return Optional.of(Range.create(comment.lineNumber(), comment.lineNumber() + 1));