Merge Android 24Q1 Release (ab/11220357)

Bug: 319669529
Merged-In: I1350ab5448f1d05b40a8a4a791e3e7227364c883
Change-Id: I58f5168509ea64b24f5c17f4024fcdaa04050e5a
diff --git a/checkstyle.py b/checkstyle.py
index b649a2d..b83b963 100755
--- a/checkstyle.py
+++ b/checkstyle.py
@@ -160,6 +160,19 @@
   if warnings:
     print('WARNINGS:\n' + '\n'.join(warnings))
 
+def _CheckForJava():
+  try:
+    java_env = os.environ.copy()
+    java_env['JAVA_CMD'] = 'java'
+    check = subprocess.Popen(['java', '--help'],
+                             stdout=subprocess.PIPE, env=java_env,
+                             universal_newlines=True)
+    stdout, _ = check.communicate()
+    stdout_lines = stdout.splitlines()
+  except OSError as e:
+    if e.errno == errno.ENOENT:
+      print('Error: Could not find `java` on path!')
+      sys.exit(1)
 
 def _ExecuteCheckstyle(java_files, classpath, config_xml):
   """Runs Checkstyle to check give Java files for style errors.
@@ -194,6 +207,7 @@
     return stdout
   except OSError as e:
     if e.errno == errno.ENOENT:
+      _CheckForJava()
       print('Error running Checkstyle!')
       sys.exit(1)