Fix ArrayIndexOutOfBoundsException on intraline diff
In some cases displaying the intraline diff fails with an exception like
this:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 10
at com.google.gerrit.prettify.common.SparseFileContent.mapIndexToLine(SparseFileContent.java:149)
at com.google.gerrit.prettify.common.PrettyFormatter.format(PrettyFormatter.java:188)
at com.google.gerrit.client.patches.AbstractPatchContentTable.getSparseHtmlFileB(AbstractPatchContentTable.java:287)
at com.google.gerrit.client.patches.SideBySideTable.render(SideBySideTable.java:113)
at com.google.gerrit.client.patches.AbstractPatchContentTable.display(AbstractPatchContentTable.java:238)
at com.google.gerrit.client.patches.PatchScreen.onResult(PatchScreen.java:444)
...
This happens when the old line is:
foo-old<LF>
and the new line is:
foo-new<CRLF>
The computed intraline diff that should be highlighted for the new file
will be 'new<CR>'. To do the highlighting 'span' tags are inserted
which separates <CR> and <LF> for the new file. The prettify parser now
replaces both with a 'br' tag. Since the number of 'br' tags is
expected to match the number of lines and we now have one 'br' too much
we run into the ArrayIndexOutOfBoundsException when looking up the lines.
Avoid this problem by removing <CR> from the intraline diff before
running the prettify parser.
Bug: issue 1759
Change-Id: I738b1c780116b890d8db8bb0ab795c6b2b72128d
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
1 file changed