Skip to content

Generated javac wrapper crashes on bash < 4.4 (macOS ships 3.2): unguarded ${LAUNCHER_ARGS[@]} #987

Description

@phuongddx

Bug: the javac wrapper scip-java generates for Maven builds (via -Dmaven.compiler.executable=<tmp>/bin/javac) crashes under bash 3.2 — the only bash macOS ships by default.

Repro: any Maven-built Java project, scip-java index, on macOS with the default /bin/bash (3.2.57):

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile
  (default-compile): Fatal error compiling: Could not retrieve version from
  <tmp>/scip-java<N>/bin/javac. Exit code 1, Output:
  <tmp>/scip-java<N>/bin/javac: line 38: LAUNCHER_ARGS[@]: unbound variable

Root cause: the generated wrapper is:

#!/usr/bin/env bash
set -eu
...
LAUNCHER_ARGS=()
...
for arg in "$@"; do
  if [[ $arg == -J* ]]; then
    LAUNCHER_ARGS+=("$arg")
  fi
done
...
javac "${JAVAC_JVM_OPTIONS[@]}" "@$NEW_JAVAC_OPTS" "${LAUNCHER_ARGS[@]}"   # line 38

LAUNCHER_ARGS only ever collects -J* flags. maven-compiler-plugin's version probe (javac -version, used to validate the configured compiler executable before the real build) invokes the wrapper with no -J flags, so the array stays empty.

Under set -u, expanding an empty array ("${arr[@]}") is an error on bash < 4.4 — confirmed directly:

$ /bin/bash --version | head -1
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25)
$ /bin/bash -c 'set -eu; A=(); echo "${A[@]}"'
/bin/bash: A[@]: unbound variable

macOS has shipped only bash 3.2 as /bin/bash for over a decade (GPLv3 licensing), and does not include a newer bash by default. This means every Maven-built Java project fails to index on macOS unless the user happens to already have a newer bash earlier on PATH than /bin/bash — the wrapper's #!/usr/bin/env bash shebang resolves through PATH, so this is enough to work around it without patching scip-java, but it shouldn't be necessary.

Both JAVAC_JVM_OPTIONS and LAUNCHER_ARGS are exposed to this on line 38.

Suggested fix: bash-3.2-safe expansion, so the wrapper works regardless of which bash version is on PATH:

javac ${JAVAC_JVM_OPTIONS[@]+"${JAVAC_JVM_OPTIONS[@]}"} "@$NEW_JAVAC_OPTS" ${LAUNCHER_ARGS[@]+"${LAUNCHER_ARGS[@]}"}

(${arr[@]+"${arr[@]}"} expands to nothing when arr is unset/empty and to the normal quoted-expansion otherwise — safe on every bash version, no set -u interaction.)

Happy to send a PR with this one-line change if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions