Skip to content

UnifiedDiffParserException on apparently sane file (2nd variant) #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
moio opened this issue Dec 14, 2020 · 13 comments
Closed

UnifiedDiffParserException on apparently sane file (2nd variant) #107

moio opened this issue Dec 14, 2020 · 13 comments
Assignees
Labels

Comments

@moio
Copy link

moio commented Dec 14, 2020

Describe the bug
UnifiedDiffReader.parseUnifiedDiff throws UnifiedDiffParserException on a patch which apparently looks good:

https://raw.githubusercontent.com/bazelbuild/bazel/master/third_party/aws-sdk-auth-lite/patches-vs-1.11.297/01-bazel-strip-unused.patch

To Reproduce
Run this program:

String patch = new Scanner(new URL(
    "https://raw.githubusercontent.com/bazelbuild/bazel/master/third_party/aws-sdk-auth-lite/patches-vs-1.11.297/01-bazel-strip-unused.patch"
).openStream(), "UTF-8").useDelimiter("\\A").next();

UnifiedDiffReader.parseUnifiedDiff(new StringBufferInputStream(patch));

Expected behavior

No Exceptions.

Actual behavior

Dec 14, 2020 9:49:46 PM com.github.difflib.unifieddiff.UnifiedDiffReader processLine
WARNING: >>> no rule matched \ No newline at end of file
Exception in thread "main" com.github.difflib.unifieddiff.UnifiedDiffParserException: expected file start line not found
at com.github.difflib.unifieddiff.UnifiedDiffReader.parse(UnifiedDiffReader.java:95)
at com.github.difflib.unifieddiff.UnifiedDiffReader.parseUnifiedDiff(UnifiedDiffReader.java:146)
...

System

  • Java version: openjdk-11
  • Version: 4.9

Notes

👋 java-diff-utils maintainers again! Here is another corner case I found. The patch comes from the Bazel project, so once again it's OK to include in tests.

@wumpz
Copy link
Collaborator

wumpz commented Dec 17, 2020

That is a nice huge diff. The new implementation of java-diff-utils will gain a lot of testing on this large file base. I will look into it.

@wumpz wumpz added the bug label Dec 17, 2020
@wumpz wumpz self-assigned this Dec 17, 2020
@wumpz wumpz pinned this issue Dec 17, 2020
@moio
Copy link
Author

moio commented Dec 18, 2020

Thanks a lot @wumpz! I might have other cases as well for you later, as I plan to test each and every patch from CentOS and likely other open source projects as well 😉

@wumpz
Copy link
Collaborator

wumpz commented Dec 18, 2020

To somehow document this: https://stackoverflow.com/questions/5813311/no-newline-at-end-of-file.

This weird

\ No newline at end of file

is put into a diff by Git to signal, that there is no linefeed at the end of the last line of this diff.

@wumpz
Copy link
Collaborator

wumpz commented Dec 18, 2020

So my implementation stores this as a flag within UnifiedDiffFile, so the write can write those lines without putting a linefeed at the end. I hope that is right.

@wumpz wumpz closed this as completed in 445381b Dec 18, 2020
@wumpz wumpz reopened this Dec 18, 2020
@wumpz wumpz closed this as completed in 642dc65 Dec 18, 2020
@wumpz
Copy link
Collaborator

wumpz commented Dec 18, 2020

Just deployed a new version.

@wumpz wumpz unpinned this issue Dec 21, 2020
@elanzini
Copy link

elanzini commented May 4, 2021

@wumpz I am still getting the same exact error when I try to parse this patch from this JIRA ticket.

@wumpz wumpz reopened this May 4, 2021
@wumpz
Copy link
Collaborator

wumpz commented May 4, 2021

@elanzini I will look into it.

@wumpz
Copy link
Collaborator

wumpz commented May 4, 2021

@elanzini May I include this patch as test data into java-diff-utils? I already solved the problem and would like to use your test data.

@elanzini
Copy link

elanzini commented May 5, 2021

@wumpz by all means! And thanks for the quick fix! I will open new issues as I find more edge cases where it breaks.

@elanzini
Copy link

elanzini commented May 5, 2021

@wumpz I found other examples for this problem pgjdbc/pgjdbc@cdeeaca or apache/cxf@1cf4fed. For both, if you try to parse the diff, you get the same complaint WARNING: >>> no rule matched \ No newline at end of file.

@wumpz
Copy link
Collaborator

wumpz commented May 5, 2021

@elanzini I included all three of your tests. They are now succeeding.

@wumpz wumpz closed this as completed in 3d5343c May 5, 2021
@williamfzc
Copy link

williamfzc commented Jul 22, 2021

same problem here :)
I just found that the latest released version (4.10) did not contain this change
When will 4.11 be released? Looking forward to it and thanks!

@wumpz
Copy link
Collaborator

wumpz commented Aug 14, 2021

Still no valid date there, since I wanted to include the new implementation of meyers linear space diff algorithm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants