angelelectrico / java-diff-utils

Automatically exported from code.google.com/p/java-diff-utils
0 stars 0 forks source link

ArrayIndexOutOfBounds exception when the text includes a line that matches the format "@@ -2,6 +2,7 @@" #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Add a line as below to the revised text.
@@ -2,6 +2,7 @@
2. Generate unified diff text.
3. Now create a 'Patch' from above diff text using DiffUtils.parseUnifiedText().
4. The following will be thrown.
    Caused by: java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at com.difflib.textdiff.difflib.Chunk.verify(Chunk.java:92)
    at com.difflib.textdiff.difflib.ChangeDelta.verify(ChangeDelta.java:91)
    at com.difflib.textdiff.difflib.ChangeDelta.applyTo(ChangeDelta.java:41)
    at com.difflib.textdiff.difflib.Patch.applyTo(Patch.java:47)
    at com.difflib.textdiff.TextDiffGenerator.applyDiff(TextDiffGenerator.java:113)
    ... 23 more

Attached the updated file DiffUtils.java with a fix.    A flag to prevent the 
processing of header line after the first time seems to fix the issue.

Original issue reported on code.google.com by meena...@gmail.com on 5 Jun 2011 at 10:10

Attachments:

GoogleCodeExporter commented 8 years ago
Add a test case for it and it looks good:

        List<String> original = new ArrayList<String>();
        List<String> revised  = new ArrayList<String>();

        original.add("test line1");
        original.add("test line2");
        original.add("test line 4");
        original.add("test line 5");

        revised.add("test line1");
        revised.add("test line2");
        revised.add("@@ -2,6 +2,7 @@");
        revised.add("test line 4");
        revised.add("test line 5");

        Patch patch = DiffUtils.diff(original, revised);
        List<String> udiff = DiffUtils.generateUnifiedDiff("original", "revised",
                original, patch, 10);
        DiffUtils.parseUnifiedDiff(udiff);

Resolving as invalid.

Original comment by dm.naume...@gmail.com on 7 Jun 2011 at 11:51