diffparser icon indicating copy to clipboard operation
diffparser copied to clipboard

The empty line is ignored

Open mrdrivingduck opened this issue 5 years ago • 3 comments

The test case is as follows:

diff --git a/source/org/jfree/data/DefaultKeyedValues.java b/source/org/jfree/data/DefaultKeyedValues.java
index 5569198..707eb0a 100644
--- a/source/org/jfree/data/DefaultKeyedValues.java
+++ b/source/org/jfree/data/DefaultKeyedValues.java
@@ -315,7 +315,9 @@ public class DefaultKeyedValues implements KeyedValues,
     public void removeValue(int index) {
         this.keys.remove(index);
         this.values.remove(index);
+        if (index < this.keys.size()) {
         rebuildIndex();
+        }
     }

     /**
@@ -330,8 +332,7 @@ public class DefaultKeyedValues implements KeyedValues,
     public void removeValue(Comparable key) {
         int index = getIndex(key);
         if (index < 0) {
-            throw new UnknownKeyException("The key (" + key 
-                    + ") is not recognised.");
+			return;
         }
         removeValue(index);
     }

There should be two hunks, but the first hunk ends at line 321, and the second hunk is completely ignored.

mrdrivingduck avatar Mar 26 '20 14:03 mrdrivingduck

Funny, I encountered a similar case a few days ago. In my case there was another diff starting right after. I think this is a bug that happens when you have an empty line inside a hunk's content, and no new line before the next diff. the parser assumes there would be an empty line before the next diff, which is not the case. As a workaround, adding an empty line before each new diff helped (append(System.lineSeparator())).

ayeletlevron avatar Mar 27 '20 16:03 ayeletlevron

Funny, I encountered a similar case a few days ago. In my case there was another diff starting right after. I think this is a bug that happens when you have an empty line inside a hunk's content, and no new line before the next diff. the parser assumes there would be an empty line before the next diff, which is not the case. As a workaround, adding an empty line before each new diff helped (append(System.lineSeparator())).

Yes, you are right. But I have a large data set of diff files so I don't want to modify them, though I have also tried your workaround and it worked. 😅 I have tried to trace the route cause and I think the route cause is here. I added an additional condition and solved my issue, but I don't know if it is a good solution.

mrdrivingduck avatar Mar 28 '20 01:03 mrdrivingduck

Yes, I got to the same root cause when I traced the issue. I had to find a workaround without changing the library..

ayeletlevron avatar Mar 29 '20 20:03 ayeletlevron