bazelbuild / rules_scala

Scala rules for Bazel
Apache License 2.0
363 stars 278 forks source link

scala compilation error with cross compilation produces additional Null Pointer Exception #1605

Closed gergelyfabian closed 2 months ago

gergelyfabian commented 2 months ago

Detecting errors for cross compilation is somehow broken, and produces an additional Null Pointer Exception.

How to reproduce:

Apply this patch in latest rules_scala code:

diff --git a/examples/crossbuild/3_select/BUILD b/examples/crossbuild/3_select/BUILD
index 2e58b6f..e5f8b7b 100644
--- a/examples/crossbuild/3_select/BUILD
+++ b/examples/crossbuild/3_select/BUILD
@@ -21,6 +21,7 @@ scala_library(
 scala_binary(
     name = "bin2",
     srcs = ["bin.scala"],
+    scalacopts = ["-Ywarn-unused-import"],
     main_class = "B",
     scala_version = "2.13.12",
     deps = [":lib"],

Then run:

cd examples/crossbuild/3_select
bazel build //3_select:bin2

This produces:

INFO: Invocation ID: 6bdd906c-b4f3-4c6e-9bf6-f9ace6cba6e8
INFO: Analyzed target //3_select:bin2 (1 packages loaded, 4 targets configured).
ERROR: /home/user/opt/rules_scala/examples/crossbuild/3_select/BUILD:21:13: scala @@//3_select:bin2 failed: (Exit 1): scalac failed: error executing Scalac command (from target //3_select:bin2) bazel-out/k8-opt-exec-ST-1e9cf9510058/bin/external/io_bazel_rules_scala/src/java/io/bazel/rulesscala/scalac/scalac @bazel-out/k8-fastbuild-ST-9386492f403d/bin/3_select/bin2.jar-0.params
scalac error: bad option: '-Ywarn-unused-import'
  scalac -help  gives more information
null
java.lang.NullPointerException
    at io.bazel.rulesscala.scalac.ScalacInvoker.invokeCompiler(ScalacInvoker.java:53)
    at io.bazel.rulesscala.scalac.ScalacWorker.compileScalaSources(ScalacWorker.java:257)
    at io.bazel.rulesscala.scalac.ScalacWorker.work(ScalacWorker.java:73)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:86)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:39)
    at io.bazel.rulesscala.scalac.ScalacWorker.main(ScalacWorker.java:33)
Target //3_select:bin2 failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.435s, Critical Path: 0.04s
INFO: 2 processes: 2 internal.

In my own project I have seen:

ERROR: /home/user/myprojest/mypackage/BUILD:42:20: scala @//myprojest/mypackage:library failed: (Exit 1): scalac failed: error executing Scalac command (from target //myprojest/mypackage:library) bazel-out/k8-opt-exec-ST-bb79e0899c0a/bin/external/io_bazel_rules_scala/src/java/io/bazel/rulesscala/scalac/scalac '--jvm_flag=-Djava.security.manager=allow' ... (remaining 1 argument skipped)
scalac error: bad option: '-Ywarn-unused-import'
  scalac -help  gives more information
Cannot invoke "scala.tools.nsc.reporters.ConsoleReporter.hasErrors()" because "reporter" is null
java.lang.NullPointerException: Cannot invoke "scala.tools.nsc.reporters.ConsoleReporter.hasErrors()" because "reporter" is null
    at io.bazel.rulesscala.scalac.ScalacInvoker.invokeCompiler(ScalacInvoker.java:53)
    at io.bazel.rulesscala.scalac.ScalacWorker.compileScalaSources(ScalacWorker.java:257)
    at io.bazel.rulesscala.scalac.ScalacWorker.work(ScalacWorker.java:73)
    at io.bazel.rulesscala.worker.Worker.persistentWorkerMain(Worker.java:86)
    at io.bazel.rulesscala.worker.Worker.workerMain(Worker.java:39)
    at io.bazel.rulesscala.scalac.ScalacWorker.main(ScalacWorker.java:33)

I suppose there may be a bug in the error handling for compiler errors.

gergelyfabian commented 2 months ago

Be aware of the probable phishing attempt above.

liucijus commented 2 months ago

Be aware of the probable phishing attempt above.

Thanks, reported