Skip to content

Commit 9655978

Browse files
authored
fix(_common): find_java picks the JDK matching the model Mendix version (TK-018) (#410)
Independent review rounds 1 to 4: APPROVE at r4. r2 fix (note before JAVA_HOME) in b027b50, r3 test fix in e6215a4. E2 field evidence: master picks JDK 21 and fails mxbuild on 11.15; this branch picks 25 and passes; 11.12 still gets 21. # #410 delta r4 (e6215a4) Scope: the one CHANGES item in 410-r3.md (order check could not fail). - Applied the exact check r3 prescribed: compare the `_jnote="$(find_java_note` line with the `JAVA_HOME="$(find_java` line, both must exist. - Head: 17 passed, 0 failed. Against b027b50~1 exec.sh and verify-model.sh: 15 passed, 2 failed (both order lines FAIL). Guard now catches the regression. - No code change outside the test. APPROVE
1 parent 902bf38 commit 9655978

6 files changed

Lines changed: 135 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Sections dated before 2026-09-19 predate the cycle and stay as they are. Named m
1919

2020
## Unreleased
2121

22+
- fix(_common): **`find_java` on macOS picks the JDK that matches the model's Mendix version: 25 for 11.14 and above, 21 below (and when the version cannot be read).** It always asked for `java_home -v 21`, a pin added for 11.12.2 (JDK 25 breaks that build's gradle 8.5). On 11.15 the same pin broke the other way: mxbuild failed `release version 25 not supported` (exit 3) on the first Java-action build, 21 times in one lab phase, until `JAVA_HOME` was set by hand in `toolkit.env`. Mendix's system requirements list JDK 21 for Studio Pro 11.13 and below and JDK 25 for 11.14 and above. The version comes from `mxtk_model_version` (the .mpr's `_MetaData`). Detection uses `java_home -F -v N`, because plain `-v N` never fails on macOS (a missing JDK silently returns the default, exit 0). When the wanted JDK is missing, the default is still used, and the new `find_java_note` line is printed by exec.sh, verify-model.sh and doctor.sh (they all discard find_java's stderr). `JAVA_HOME` still wins; `MXTK_JAVA_HOME_BIN` overrides the java_home binary for tests. `tests/wave2/test-find-java-version.sh` (fake java_home that mimics the real fallback-with-exit-0, 14 cases) fails on master for 11.14, 11.15 and 12.x. Not run: a real two-JDK Mac build; the version table is taken from the Mendix docs. Field report: a five-app lab project (Mendix 11.15, mxcli v0.26.0), TK-018 — MendixMau
2223
- learn(workflow skills): **a Jump has one fixed target, so one failure handler for N steps is a child workflow, not a shared node; plus three probed workflow errors (CE0117 on a `System.Workflow` argument means map `$WorkflowInstance`, CE1613 means the called workflow's parameter must be `$WorkflowContext`, and `returns` goes before `exposed as workflow action`).** `workflow-structure-rules.md` §1 and `learned-workflow-patterns.md` §9. The §9 rows were probed on mxcli v0.26.0 / Mendix 11.15.0 with native `mx check`. The third row corrects the reading that a called microflow cannot return a value. Upstream issues: mendixlabs/mxcli#1529 (CE0117), #1530 (CE1613, and `syntax workflow call-workflow` shows the failing form), #1531 (describe drops every call workflow mapping), #1533 (`returns` parse messages). Source: a five-app lab project (Mendix 11.15, mxcli v0.26.0) — five-app lab report, WF-1
2324
- learn(fixture-seeding): **resetting workflow data: abort instances through the runtime (Workflow Commons admin or *Change workflow state*); if SQL is unavoidable, delete the link tables first (`system$workflow_currentactivity`, `system$workflow_workflowdefinition`, `system$workflowusertask_assignees`, `system$workflowusertask_targetusers`, `system$workflowusertask_targetgroups`, plus the `system$workflowendedusertask_*` equivalents; names read from a Mendix 11.15 database), and reset a context object only after its instances are gone.** A seed reset that deleted workflow rows by SQL failed on those links (WF-5). Text only, `ondemand` skill. — five-app lab report, WF-5
2425
- fix(e2e/helpers): **`navTo` throws `navigation item "<title>" not found` instead of clicking nothing.** A missing menu item was a silent no-op, so when the target page was also the persona's home page the landing guard stayed green and a broken-control journey (a control that must FAIL) passed. The parent group stays soft (an open flyout needs no click); the item itself must be found. The message names the active user and the visible menu items, so the reader can tell a renamed item (fix the journey) from a role that cannot open the page (fix the grants). Callers: journey steps fail with the message, design-audit rung 7 records a fault, full-app-walkthrough records a failed `nav` step (the walk stops only when the step is `fatal`), monkey's `land` swallows the error and still checks `.mx-page`, so monkey is unchanged. `tests/wave2/test-navto-missing-item.sh` (stub page, no browser) fails on master (absent item resolves) and passes here. Field report: a five-app lab project (Mendix 11.15, mxcli v0.26.0), TK-012 — MendixMau

‎bin/doctor.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ MXBUILD="$(find_mxbuild 2>/dev/null || true)"
606606
JAVA_HOME_FOUND="$(find_java 2>/dev/null || true)"
607607
JAVA_EXE="$(find_java_exe 2>/dev/null || true)"
608608

609+
_jnote="$(find_java_note 2>/dev/null || true)"
610+
609611
# toolkit.env — the human-editable answer to "doctor guessed the wrong Studio Pro / Java".
610612
# _common.sh already loaded it (project file, then ~/.mxcli-toolkit.env; a variable set in
611613
# the shell wins over both). Say what was read, so a stale value is findable.
@@ -843,6 +845,7 @@ if [ -n "$JAVA_EXE" ] && [ -x "$JAVA_EXE" ]; then
843845
JV="$("$JAVA_EXE" -version 2>&1 | grep -i 'version' | head -1)" || JV=""
844846
if [ -n "$JV" ]; then
845847
ok "java runs: $JV ($JAVA_EXE)"
848+
[ -z "${_jnote:-}" ] || warn "$_jnote"
846849
# mxbuild compiles the model's Java actions, which takes javac — a JRE has none. Studio
847850
# Pro's bundled runtime is a JRE that mxbuild is paired with, so only flag a system Java.
848851
case "$JAVA_HOME_FOUND" in

‎project-bin/_common.sh‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,32 @@ find_mxbuild() {
485485
return 1
486486
}
487487

488+
# _mxtk_java_want — the JDK major the model's Mendix version needs: 25 for 11.14 and above,
489+
# else 21 (also when the version cannot be read).
490+
_mxtk_java_want() {
491+
local mver mmaj mmin want=21
492+
if mver=$(mxtk_model_version 2>/dev/null); then
493+
mmaj="${mver%%.*}"; mmin="${mver#*.}"; mmin="${mmin%%.*}"
494+
if [ "$mmaj" -gt 11 ] 2>/dev/null || { [ "$mmaj" -eq 11 ] && [ "$mmin" -ge 14 ]; } 2>/dev/null; then want=25; fi
495+
fi
496+
echo "$want"
497+
}
498+
499+
# find_java_note — prints ONE line when find_java had to use a JDK other than the one the
500+
# model needs (macOS, JAVA_HOME unset, wanted JDK not installed); prints nothing otherwise.
501+
# find_java runs in a $(...) whose stderr every caller discards, so the warning has to be a
502+
# separate call the caller prints:
503+
# _n="$(find_java_note || true)"; [ -n "$_n" ] && echo "WARN: $_n" >&2
504+
find_java_note() {
505+
[ -n "${JAVA_HOME:-}" ] && [ -d "$JAVA_HOME" ] && return 0
506+
local jhbin="${MXTK_JAVA_HOME_BIN:-/usr/libexec/java_home}" want used
507+
[ "$(mxtk_platform)" = macos ] && [ -x "$jhbin" ] || return 0
508+
want=$(_mxtk_java_want)
509+
"$jhbin" -F -v "$want" >/dev/null 2>&1 && return 0
510+
used=$(find_java 2>/dev/null) || used="none found"
511+
echo "wanted JDK $want (for this model's Mendix version) is not installed, using $used; mxbuild may fail with a Java version error. Install JDK $want or set JAVA_HOME in toolkit.env."
512+
}
513+
488514
# find_java — JAVA_HOME for the mxbuild invocation. $JAVA_HOME wins if already set.
489515
#
490516
# /usr/libexec/java_home is a macOS binary and does not exist anywhere else, so on
@@ -494,11 +520,22 @@ find_mxbuild() {
494520
find_java() {
495521
if [ -n "${JAVA_HOME:-}" ] && [ -d "$JAVA_HOME" ]; then echo "$JAVA_HOME"; return 0; fi
496522
local app jh
497-
# JDK 21 first on macOS: with JDK 25 as the default, the Mendix 11 deploy build's gradle
498-
# 8.5 fails ("Unsupported class file major version 69", mxbuild exit 3, empty problems[])
499-
# — field project 2026-09-26, Mendix 11.12.2. Platform-guarded: java_home is mac-only.
500-
if [ "$(mxtk_platform)" = macos ] && [ -x /usr/libexec/java_home ]; then
501-
jh=$(/usr/libexec/java_home -v 21 2>/dev/null || /usr/libexec/java_home 2>/dev/null) && [ -n "$jh" ] && { echo "$jh"; return 0; }
523+
# macOS: the JDK that matches the model. Studio Pro 11.13 and below build with JDK 21 (with
524+
# JDK 25 as the default, the deploy build's gradle 8.5 fails: "Unsupported class file major
525+
# version 69", mxbuild exit 3, empty problems[] — field project 2026-09-26, Mendix 11.12.2);
526+
# 11.14 and above need JDK 25 (Gradle 9.1+; "release version 25 not supported" on JDK 21 —
527+
# field report, Mendix 11.15; docs.mendix.com/refguide/system-requirements). The model's
528+
# version is read from the .mpr; unreadable → want 21 as before.
529+
# Plain `java_home -v N` NEVER fails on macOS: when N is not installed it prints the default
530+
# JDK and exits 0. Only `-F -v N` fails, so detection uses -F. A missing wanted JDK still
531+
# falls back to the default (nothing new blocks), and find_java_note says so, because every
532+
# caller discards find_java's stderr. Platform-guarded: java_home is mac-only.
533+
# MXTK_JAVA_HOME_BIN overrides the binary (tests).
534+
local jhbin="${MXTK_JAVA_HOME_BIN:-/usr/libexec/java_home}" want
535+
if [ "$(mxtk_platform)" = macos ] && [ -x "$jhbin" ]; then
536+
want=$(_mxtk_java_want)
537+
jh=$("$jhbin" -F -v "$want" 2>/dev/null) && [ -n "$jh" ] && { echo "$jh"; return 0; }
538+
jh=$("$jhbin" 2>/dev/null) && [ -n "$jh" ] && { echo "$jh"; return 0; }
502539
fi
503540
# Studio Pro's bundled JRE.
504541
if app=$(find_sp_app 2>/dev/null); then

‎project-bin/exec.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,8 @@ MXBUILD="$(mxtk_ensure_mxbuild "$MPR" || true)"
10311031
# below failed its -x test and the entire mxbuild block was skipped on every run.
10321032
# find_java/find_java_exe (project-bin/_common.sh) resolve per platform and prefer
10331033
# Studio Pro's own bundled JRE, which is the one paired with this mxbuild.
1034+
# The note comes first: once JAVA_HOME is assigned below, find_java_note sees it set and stays silent.
1035+
_jnote="$(find_java_note 2>/dev/null || true)"; [ -z "$_jnote" ] || echo "⚠ $_jnote" >&2
10341036
JAVA_HOME="$(find_java 2>/dev/null || true)"
10351037
JAVA_EXE="$(find_java_exe 2>/dev/null || true)"
10361038

‎project-bin/verify-model.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ STAMP=1; [ "${1:-}" = "--no-stamp" ] && STAMP=0
2929
WHY=""
3030

3131
MXBUILD="$(mxtk_ensure_mxbuild "$MPR" || true)"
32+
# The note comes first: once JAVA_HOME is assigned below, find_java_note sees it set and stays silent.
33+
_jnote="$(find_java_note 2>/dev/null || true)"; [ -z "$_jnote" ] || echo "⚠ $_jnote" >&2
3234
JAVA_HOME="$(find_java 2>/dev/null || true)"
3335
JAVA_EXE="$(find_java_exe 2>/dev/null || true)"
3436
if [ ! -x "${MXBUILD:-/nonexistent}" ] || [ ! -x "${JAVA_EXE:-/nonexistent}" ]; then
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
# test-find-java-version.sh — find_java picks the JDK that matches the model's Mendix version
3+
# (TK-018, field report from a five-app lab project, Mendix 11.15, mxcli v0.26.0).
4+
# usage: bash tests/wave2/test-find-java-version.sh project-bin/_common.sh
5+
# Studio Pro 11.13 and below: JDK 21; 11.14 and above: JDK 25 (docs.mendix.com/refguide/
6+
# system-requirements). Before: always `java_home -v 21`, so an 11.15 build died with
7+
# "release version 25 not supported". A fake java_home stands in for /usr/libexec/java_home and
8+
# the platform and model version are stubbed, so this runs anywhere.
9+
set -u
10+
COMMON="${1:?usage: $0 project-bin/_common.sh}"
11+
COMMON="$(cd "$(dirname "$COMMON")" && pwd)/$(basename "$COMMON")"
12+
T="$(mktemp -d "${TMPDIR:-/tmp}/mxtk-findjava.XXXXXX")"; trap 'rm -rf "$T"' EXIT
13+
# Mimics the REAL macOS /usr/libexec/java_home: plain `-v N` for a version that is not installed
14+
# falls back to the default JDK and exits 0; only `-F -v N` fails (exit 1). MXTK_FAKE_JDKS lists
15+
# the installed majors (default "21 25"); the default JDK is the highest.
16+
cat > "$T/java_home" <<'SH'
17+
#!/bin/sh
18+
JDKS="${MXTK_FAKE_JDKS:-21 25}"; FAIL=0; V=""
19+
while [ $# -gt 0 ]; do case "$1" in -F) FAIL=1;; -v) V="$2"; shift;; esac; shift; done
20+
default=""; for j in $JDKS; do default="$j"; done
21+
if [ -n "$V" ]; then
22+
for j in $JDKS; do [ "$j" = "$V" ] && { echo "/jdk/$j"; exit 0; }; done
23+
[ "$FAIL" = 1 ] && { echo "Unable to locate a Java Runtime." >&2; exit 1; }
24+
fi
25+
echo "/jdk/$default"
26+
SH
27+
chmod +x "$T/java_home"
28+
PASS=0; FAIL=0
29+
run() { # <model version|none> -> prints find_java result
30+
( unset JAVA_HOME; export MXTK_JAVA_HOME_BIN="$T/java_home"
31+
# shellcheck disable=SC1090
32+
. "$COMMON" >/dev/null 2>&1
33+
mxtk_platform() { echo macos; }
34+
MV="$1"; if [ "$MV" = none ]; then mxtk_model_version() { return 1; }; else mxtk_model_version() { echo "$MV"; }; fi
35+
find_java ) 2>/dev/null
36+
}
37+
note() { # <model version> -> prints find_java_note output
38+
( unset JAVA_HOME; export MXTK_JAVA_HOME_BIN="$T/java_home"
39+
# shellcheck disable=SC1090
40+
. "$COMMON" >/dev/null 2>&1
41+
mxtk_platform() { echo macos; }
42+
MV="$1"; mxtk_model_version() { echo "$MV"; }
43+
find_java_note ) 2>/dev/null
44+
}
45+
checknote() { # <label> <model> <want substring or EMPTY>
46+
got="$(note "$2")"
47+
if { [ "$3" = EMPTY ] && [ -z "$got" ]; } || { [ "$3" != EMPTY ] && case "$got" in *"$3"*) true;; *) false;; esac; }; then
48+
PASS=$((PASS+1)); echo " ok $1"; else FAIL=$((FAIL+1)); echo " FAIL $1 -> '$got'"; fi
49+
}
50+
check() { got="$(run "$1")"; if [ "$got" = "$2" ]; then PASS=$((PASS+1)); echo " ok model $1 -> $got"; else FAIL=$((FAIL+1)); echo " FAIL model $1 -> '$got' (want $2)"; fi; }
51+
check 11.15.0 /jdk/25
52+
check 11.14.0 /jdk/25
53+
check 11.13.2 /jdk/21
54+
check 11.12.2 /jdk/21
55+
check 10.24.3 /jdk/21
56+
check 12.0.0 /jdk/25
57+
check none /jdk/21
58+
# Only JDK 21 installed, 11.15 model: java_home -v 25 would silently return 21 (real macOS), so
59+
# the mismatch has to be reported, and find_java still falls back (no new blocking path).
60+
export MXTK_FAKE_JDKS="21"
61+
check 11.15.0 /jdk/21
62+
checknote "11.15 model, only JDK 21: mismatch reported" 11.15.0 "wanted JDK 25"
63+
checknote "11.15 model, only JDK 21: note names the JDK used" 11.15.0 "using /jdk/21"
64+
checknote "11.12 model, JDK 21 present: no note" 11.12.2 EMPTY
65+
export MXTK_FAKE_JDKS="25"
66+
checknote "11.12 model, only JDK 25: mismatch reported" 11.12.2 "wanted JDK 21"
67+
export MXTK_FAKE_JDKS="21 25"
68+
checknote "11.15 model, both JDKs: no note" 11.15.0 EMPTY
69+
# the exec.sh / verify-model.sh caller sequence: the note is taken BEFORE JAVA_HOME is assigned
70+
# (after it, find_java_note sees JAVA_HOME set and always stays silent)
71+
MXTK_FAKE_JDKS=21
72+
for f in exec.sh verify-model.sh; do
73+
a=$(grep -n '^_jnote="\$(find_java_note' "$(dirname "$COMMON")/$f" | head -1 | cut -d: -f1)
74+
b=$(grep -n '^JAVA_HOME="\$(find_java' "$(dirname "$COMMON")/$f" | head -1 | cut -d: -f1)
75+
[ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ] \
76+
&& { PASS=$((PASS+1)); echo " ok $f: note computed before JAVA_HOME is set"; } \
77+
|| { FAIL=$((FAIL+1)); echo " FAIL $f: note computed after JAVA_HOME is set"; }
78+
done
79+
got="$( unset JAVA_HOME; export MXTK_JAVA_HOME_BIN="$T/java_home"; . "$COMMON" >/dev/null 2>&1; mxtk_platform() { echo macos; }; mxtk_model_version() { echo 11.15.0; }
80+
_jnote="$(find_java_note 2>/dev/null || true)"; JAVA_HOME="$(find_java 2>/dev/null || true)"; echo "$_jnote" )"
81+
case "$got" in *"wanted JDK 25"*) PASS=$((PASS+1)); echo " ok caller sequence: 11.15 model, only JDK 21: note reaches exec.sh/verify-model.sh";; *) FAIL=$((FAIL+1)); echo " FAIL caller sequence -> '$got'";; esac
82+
# explicit JAVA_HOME wins and needs no note
83+
got="$( export JAVA_HOME="$T" MXTK_FAKE_JDKS=21 MXTK_JAVA_HOME_BIN="$T/java_home"; . "$COMMON" >/dev/null 2>&1; mxtk_platform() { echo macos; }; mxtk_model_version() { echo 11.15.0; }; echo "$(find_java)|$(find_java_note)" 2>/dev/null )"
84+
if [ "$got" = "$T|" ]; then PASS=$((PASS+1)); echo " ok explicit JAVA_HOME wins, no note"; else FAIL=$((FAIL+1)); echo " FAIL JAVA_HOME -> '$got'"; fi
85+
echo "$PASS passed, $FAIL failed"; [ "$FAIL" = 0 ]

0 commit comments

Comments
 (0)