Handle case where checkstyle does not return 2 lines.
Typically this happens due to a crash in the jar file.
Bug: b/160796554
Merged-in: Ia27b93eafd7471f3886e4d3a4080a63dc5e8e935
Change-Id: Ia27b93eafd7471f3886e4d3a4080a63dc5e8e935
diff --git a/checkstyle.py b/checkstyle.py
index 9733848..85a5d90 100755
--- a/checkstyle.py
+++ b/checkstyle.py
@@ -182,9 +182,12 @@
stdout=subprocess.PIPE, env=checkstyle_env,
universal_newlines=True)
stdout, _ = check.communicate()
+ stdout_lines = stdout.splitlines()
# A work-around for Checkstyle printing error count to stdio.
- if '</checkstyle>' in stdout.splitlines()[-2]:
- stdout = '\n'.join(stdout.splitlines()[:-1])
+ if len(stdout_lines) < 2:
+ stdout = stdout_lines[0]
+ elif len(stdout_lines) >= 2 and '</checkstyle>' in stdout_lines[-2]:
+ stdout = '\n'.join(stdout_lines[:-1])
return stdout
except OSError as e:
if e.errno == errno.ENOENT: