Fix NPE when JACOCO_METADATA_JAR is not set.
This happens when a sh_test has a dependency on a java_binary, so
JACOCO_METADATA_JAR is not set and coverage should not be run on the
java_binary.
RELNOTES: None.
@@ -293,7 +293,8 @@ public class JacocoCoverageRunner {
public static void main(String[] args) throws Exception {
final String metadataFile = System.getenv("JACOCO_METADATA_JAR");
- final boolean isNewImplementation = metadataFile.endsWith(".txt");
+ final boolean isNewImplementation =
+ metadataFile == null ? false : metadataFile.endsWith(".txt");
final String javaRunfilesRoot = System.getenv("JACOCO_JAVA_RUNFILES_ROOT");
final String coverageReportBase = System.getenv("JAVA_COVERAGE_FILE");
@@ -353,6 +354,7 @@ public class JacocoCoverageRunner {
}
File[] metadataJars;
+ if (metadataFile != null) {
if (isNewImplementation) {
List<String> metadataFiles = Files.readLines(new File(metadataFile), UTF_8);
List<File> convertedMetadataFiles = new ArrayList<>();
@@ -365,7 +367,9 @@ public class JacocoCoverageRunner {
}
new JacocoCoverageRunner(
- isNewImplementation, dataInputStream, coverageReport, metadataJars).create();
+ isNewImplementation, dataInputStream, coverageReport, metadataJars)
+ .create();
+ }
} catch (IOException e) {
e.printStackTrace();
Runtime.getRuntime().halt(1);
