Handle case where checkstyle does not return 2 lines. am: e1510db8d1
Original change: https://googleplex-android-review.googlesource.com/c/platform/prebuilts/checkstyle/+/12129281
Change-Id: I594668e90f24bde6cb5cc344e2dac18430c427fb
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: