Skip to content

UnifiedDiffParserException: expected file start line not found occurred when parse one Git format patch file #84

@HuGanghui

Description

@HuGanghui

Describe the bug
UnifiedDiffParserException: expected file start line not found occured when parse one Git format patch file

To Reproduce
Steps to reproduce the behavior:

  1. Example data
  2. simple programm snippet
  3. See error

the git format patch file is here:

From b53e612a2ab5ff15d14860e252f84c0f343fe93a Mon Sep 17 00:00:00 2001
From: nmancus1 <nmancus1
Date: Thu, 4 Jun 2020 11:46:34 -0400
Subject: [PATCH] minor: Add input file for Java14 instanceof with pattern
 matching (#7290)

---
 config/ant-phase-verify.xml                        |  2 +
 .../InputJava14InstanceofWithPatternMatching.java  | 76 ++++++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java14/InputJava14InstanceofWithPatternMatching.java

diff --git a/config/ant-phase-verify.xml b/config/ant-phase-verify.xml
index d27ffef..e0285ce 100644
--- a/config/ant-phase-verify.xml
+++ b/config/ant-phase-verify.xml
@@ -148,6 +148,8 @@
          <exclude name="**/InputMainFrameModelIncorrectClass.java"/>
          <exclude name="**/InputBeforeExecutionExclusionFileFilterIncorrectClass.java"/>
          <exclude name="**/InputJavaParser.java"/>
+         <!-- until https://github.com/checkstyle/checkstyle/issues/7290 -->
+         <exclude name="**/InputJava14InstanceofWithPatternMatching.java"/>
          <!-- Cannot parse until Java 14 support -->
          <exclude name="**/InputJava14Records.java"/>
         </fileset>
diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java14/InputJava14InstanceofWithPatternMatching.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java14/InputJava14InstanceofWithPatternMatching.java
new file mode 100644
index 0000000..8fa3eba
--- /dev/null
+++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java14/InputJava14InstanceofWithPatternMatching.java
@@ -0,0 +1,76 @@
+//non-compiled with javac: Compilable with Java14
+package com.puppycrawl.tools.checkstyle.grammar.java14;
+
+import java.util.Arrays;
+import java.util.Locale;
...... I removed it
+        }
+    }
+}
--
2.7.4

when I run the follow codes, the exception happened in UnifiedDiffReader.parseUnifiedDiff

final String fullFileName = getPath(fileName);
        final FileInputStream ins = new FileInputStream(fullFileName);
        return UnifiedDiffReader.parseUnifiedDiff(ins);

error information:

com.github.difflib.unifieddiff.UnifiedDiffParserException: expected file start line not found

	at com.github.difflib.unifieddiff.UnifiedDiffReader.parse(UnifiedDiffReader.java:90)
	at com.github.difflib.unifieddiff.UnifiedDiffReader.parseUnifiedDiff(UnifiedDiffReader.java:136)
	at com.github.checkstyle.patchfilter.SuppressionPatchFilterTest.getUnifiedDiff(SuppressionPatchFilterTest.java:232)
	at com.github.checkstyle.patchfilter.SuppressionPatchFilterTest.testGitFormatPatchLinuxTwo(SuppressionPatchFilterTest.java:151)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Expected behavior
A clear and concise description of what you expected to happen.

I hope to parse this file correctly.
System

  • Java version 1.8
  • Version [e.g. 22]
    Maven plugin
  <groupId>io.github.java-diff-utils</groupId>
  <artifactId>java-diff-utils</artifactId>
  <version>4.5</version>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions