bazel icon indicating copy to clipboard operation
bazel copied to clipboard

java_library and java_binary with empty java file fails with confusing error message

Open hhclam opened this issue 11 years ago • 5 comments

$ 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.

hhclam avatar Sep 26 '15 03:09 hhclam

This is probably a minor issue but a meaningful error message is helpful.

hhclam avatar Sep 26 '15 03:09 hhclam

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?

philwo avatar Sep 27 '15 08:09 philwo

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.

cushon avatar Sep 28 '15 15:09 cushon

See also #379

cushon avatar Sep 28 '15 15:09 cushon

Fixed by 197ffd811cf2be8047674c3c5d492adee866ecd8.

cushon avatar Oct 01 '15 05:10 cushon