hashicorp/nomad · error

failed check for macOS jvm: %v, out: %v

Error message

failed check for macOS jvm: %v, out: %v

What it means

On darwin, the driver probes for a JVM by running macOSJavaTestCommand (an external shell command) and capturing combined output. If that command exits non-zero, checkForMacJVM fails with this error, embedding both the exec error and the command output (with quotes/newlines escaped). It propagates up wrapped by 'failed to check java version'.

Source

Thrown at drivers/java/utils.go:26

	"fmt"
	"os/exec"
	"regexp"
	rt "runtime"
	"strings"
)

var javaVersionCommand = []string{"java", "-version"}
var macOSJavaTestCommand = "/usr/libexec/java_home"

func checkForMacJVM() (ok bool, err error) {
	// test for java differently because of the shim application
	var out bytes.Buffer
	cmd := exec.Command(macOSJavaTestCommand)
	cmd.Stdout = &out
	cmd.Stderr = &out
	err = cmd.Run()
	if err != nil {
		err = fmt.Errorf("failed check for macOS jvm: %v, out: %v", err, strings.ReplaceAll(strings.ReplaceAll(out.String(), "\n", " "), `"`, `\"`))
		return false, err
	}
	return true, nil
}

func javaVersionInfo() (version, runtime, vm string, err error) {
	var out bytes.Buffer

	if rt.GOOS == "darwin" {
		_, err = checkForMacJVM()
		if err != nil {
			err = fmt.Errorf("failed to check java version: %v", err)
			return
		}
	}

	cmd := exec.Command(javaVersionCommand[0], javaVersionCommand[1:]...)
	cmd.Stdout = &out

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Install a JDK on the macOS host (brew install --cask temurin) so the java_home probe succeeds.
  2. Run the probe command manually (/usr/libexec/java_home -V) and read the embedded 'out:' text in the error for the exact reason.
  3. Point JAVA_HOME at a valid JDK or reinstall after an OS upgrade.
Defensive patterns

Strategy: try-catch

Validate before calling

if runtime.GOOS == "darwin" {
    if out, err := exec.Command("/usr/libexec/java_home", "-V").CombinedOutput(); err != nil {
        return fmt.Errorf("no macOS JVM: %v: %s", err, out)
    }
}

Try / catch

ok, err := checkForMacJVM()
if err != nil {
    // err already embeds probe output; log and mark driver unhealthy
    logger.Error("macOS JVM probe failed", "error", err)
    return
}

Prevention

When it happens

Trigger: javaVersionInfo() on macOS invokes checkForMacJVM; the probe command (e.g. /usr/libexec/java_home) fails — no JVM installed, Xcode command-line tools missing, or the helper returns an error.

Common situations: Mac Nomad client without a JDK; /usr/libexec/java_home failing after a macOS upgrade; java_home returning 'Unable to find any JVMs matching version'; corrupt JAVA_HOME.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/c3682625b6c92a55. Report an issue: GitHub.