java_library and java_binary with empty java file fails with confusing error message
$ touch dummy.java $ cat BUILD java_library( name = "test", srcs = ["dummy.java"], ) $ bazel build :test
The above build command would fail with: NFO: Found 1 target... INFO: From Building libtest.jar (1 files): Expected at least one FLOW event BazelJavaBuilder threw exception: java compilation returned status ABNORMAL ERROR: /net/hsalpha/userhome/alpha/Projects/bazel-fail2/BUILD:1:1: Java compilation in rule '//:test' failed: java failed: error executing command external/local-jdk/bin/java -Xbootclasspath/p:third_party/java/jdk/langtools/javac.jar -client -jar tools/jdk/JavaBuilder_deploy.jar @bazel-out/local_linux-fastbuild/bin/libtest.jar-2.params: com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1. Target //:test failed to build Use --verbose_failures to see the command lines of failed build steps.
The command should choose to not fail or output a more meaningful error message that suggests the user to check the source files.
This is probably a minor issue but a meaningful error message is helpful.
Liam, is this something we can improve on the JavaBuilder side?
Some thoughts: Running "javac" on an empty file doesn't produce any output files and also doesn't print anything to the console. The exit code is 0. (If JavaBuilder would act in the same way, Bazel would then immediately fail because an expected output artifact wasn't generated by the compile action.)
The "Expected at least one FLOW event" message is generated here: https://github.com/bazelbuild/bazel/blob/master/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java#L156
If this strictly maps to "the input file was empty", maybe we can simply make that message more user-friendly?
Sorry for the trouble. This was a mistake on my end, the assertion was meant to be impossible. But the language spec says that empty files are valid Java programs, so we should be allowing them.
@eaftan has a fix out for review.
See also #379
Fixed by 197ffd811cf2be8047674c3c5d492adee866ecd8.