Java execution errors on the test operation of the daml tool when run in a bazel sandbox

I created bazel build rules for the daml tool operations from the sdk. The sdk is set up hermetically from its tar bal as an external bazel workspace and the tools from the sdk are wired into a bazel toolchain.

When the test rule executes daml test during the bazel test execution, I see these error messages:

on macos:

damlc: ScenarioServiceException "Failed to run java: fd:21:                                                       
hGetContents: invalid argument (invalid byte sequence)"                                                           

and on some linux configurations:

damlc: ScenarioServiceException "Failed to run java: java:                                                         
readCreateProcessWithExitCode: posix_spawnp:                                                                       
does not exist (No such file or directory)"                                                                        

while on other linux configurations the test just works fine. This is all under bazel 5.0.0 with the daml sdk 1.18.1. Directly executing the test executable that bazel creates always works.

I suspect it’s an interaction with the bazel sandbox, but I don’t know where those error messages come from, so I don’t quite understand what exactly is missing or misplaced inside the sandbox.

Do those error messages ring a bell with anyone who could point me to the place they are from?

Thanks a lot!

If JAVA_HOME is set, we use that to locate java. If not which seems to be the case here, we just assume it is in PATH. So you need to setup your bazel rules such that JAVA is in path before calling daml test.

Thanks a lot, that already helps!

I now set JAVA_HOME to point to bazel’s default runtime toolchain. On macos, this changes the error message to

damlc: ScenarioServiceException "Failed to run java: external/local_jdk/bin/java:
readCreateProcessWithExitCode: posix_spawnp: failed (Undefined error: 0)"

Using another toolchain version, e.g. --java_runtime_version=remotejdk_11 yields the same error:

damlc: ScenarioServiceException "Failed to run java: external/remotejdk11_macos_aarch64/bin/java:
readCreateProcessWithExitCode: posix_spawnp: failed (Undefined error: 0)"

Does this ring a bell?

Generally, which JDK version should I use with the DAML SDK?

OK, I found the remaining error: the value of JAVA_HOME must be an absolute path. If it’s relative (i.e. what bazel would give you) and valid from the working directory when damlc is invoked, it won’t work.

Apparently damlc internally either changes its working dir, or resolves a relative value of JAVA_HOME against another directly than the current one at invocation time. Perhaps --project-root?

Anyway, this is solved for me now.


1 Like

Yes --project-root changes the working directory so that’s where things break.

I had the same error today and took a while to realise it was because my JAVA_HOME wasn’t set correctly (found it here actually) :joy:

Can the error message be more helpful / indicate that JAVA_HOME not being set is the obvious thing the user should check ?