Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gergelyfabian opened this issue Aug 26, 2024 · 2 comments · Fixed by #1606

Comments

@gergelyfabian
Copy link
Contributor

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
Copy link
Contributor Author

gergelyfabian commented Aug 26, 2024

Be aware of the probable phishing attempt above.

@liucijus
Copy link
Collaborator

Be aware of the probable phishing attempt above.

Thanks, reported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants
@liucijus @gergelyfabian and others