You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we have 2 list in specific order, ListDiff#accept may handle the ListDiffEntry list created by Diffs#computeListDiff incorrectly which results in IndexOutOfBoundException.
Recreation step : Running the attached snippet will reproduce the issue
Attached a snippet and output from the snippet below to explain the issue. Diffs#computeListDiff correctly generates the ListDiffEntry list and while processing the list accept() method clubs the 1st and 2nd entry together incorrectly, however it should be considering the 2nd and 3rd entry together as computeListDiff created 2nd and 3rd entry together to consider this for move(There is a code comment in Diffs#createListDiffs() to mention the move)
Based on the accept() method java doc it calls the handleReplace() if add entry is adjacent to remove entry, in this case it calculated the 2nd entries position as 1st entry and processing as replace.
Expected behaviour:
To correctly process the list it should call the handleAdd() first then handleMove() for 2nd and 3rd entry together followed by handleMove() for 4th and 5th entry then handleAdd() for 6th entry and 7th entry.
Proposed Code Change:
Before calling the visitor.handleReplace() it should check the next to next entry to confirm it is not same element as the next entry element.
When we have 2 list in specific order, ListDiff#accept may handle the ListDiffEntry list created by Diffs#computeListDiff incorrectly which results in IndexOutOfBoundException.
Recreation step : Running the attached snippet will reproduce the issue
Attached a snippet and output from the snippet below to explain the issue. Diffs#computeListDiff correctly generates the ListDiffEntry list and while processing the list accept() method clubs the 1st and 2nd entry together incorrectly, however it should be considering the 2nd and 3rd entry together as computeListDiff created 2nd and 3rd entry together to consider this for move(There is a code comment in Diffs#createListDiffs() to mention the move)
Based on the accept() method java doc it calls the handleReplace() if add entry is adjacent to remove entry, in this case it calculated the 2nd entries position as 1st entry and processing as replace.
Expected behaviour:
To correctly process the list it should call the handleAdd() first then handleMove() for 2nd and 3rd entry together followed by handleMove() for 4th and 5th entry then handleAdd() for 6th entry and 7th entry.
Proposed Code Change:
Before calling the visitor.handleReplace() it should check the next to next entry to confirm it is not same element as the next entry element.
Current Code - ListDiff#accept()
After Change - ListDiff#accept()
Attached the snippet to recreate the issue
ListDiffSnippet.txt
Snippet generates the following output.
The text was updated successfully, but these errors were encountered: