Skip to content

exec resolves the result type of a generic Java action call from the wrong type parameter when it is bound through entity <T> (check passes; with one type parameter it writes sum … by ;, CE0015) #1986

Done

Description

@TomNiesConclusion

1. mxcli version: v0.34.0 (2026-11-27T16:31:14Z) (Windows 11, amd64); A and B also on nightly-20261127-90b599447
2. Mendix version: 11.12.7
Repro app: a fresh mxcli new app, built by the script below

3. Scenario

A generic Java action RetrieveFor<InputType, ResultType>(ObjectList: List of InputType, RetrieveEntity: entity <ResultType>) returns List of ResultType is called with a list of Sales.Customer and RetrieveEntity = 'Sales.Order'. exec types the result as List of Sales.Customer (the type of the other type parameter), so sum $OrderList by Amount is refused with "Sales.Customer has no member Amount". mxcli check --references says "Check passed!" for the same script. It does not matter whether the entity <T> argument is a persistent entity (A) or a view entity (B). With only one type parameter (C), exec does not refuse but writes the aggregate with an empty attribute (sum $OrderList by ;), which mx check reports as CE0015. mx check itself does type the result as List of Sales.Order (D builds without errors).

Related, but different: #1404 (type parameters on the action definition), #1909 (missing argument / mismatching result type of a CALL JAVA ACTION), #1908 (view entity columns in check).

Self-contained repro, run in an empty directory:

#!/usr/bin/env bash
# Repro: exec resolves the result type of a generic Java action call wrongly when the
# type parameter is bound through an `entity <T>` argument. Needs mxcli.
set -e
cd "$(dirname "$0")"
export MXCLI_LOG_DIR="$PWD/logs"
P=Repro/Repro.mpr
mxcli new Repro --version 11.12.7 --skip-build > /dev/null

# Domain model, a view entity and two generic Java actions:
#   RetrieveFor<InputType, ResultType>(ObjectList: List of InputType, RetrieveEntity: entity <ResultType>) returns List of ResultType
#   RetrieveAll<ResultType>(RetrieveEntity: entity <ResultType>) returns List of ResultType
cat > step1.mdl <<'MDL'
mdl 1;
create module Sales;
create persistent entity Sales.Customer ( Name: String(100) );
create persistent entity Sales."Order" ( Amount: Integer );
create association Sales.Order_Customer from Sales."Order" to Sales.Customer;
create view entity Sales.CustomerStats (
  OrderCount: Integer,
  TotalAmount: Integer
) as (
  select c.ID as CustomerStats_Customer, count(o.ID) as OrderCount, sum(o.Amount) as TotalAmount
  from Sales."Order" as o
  join o/Sales.Order_Customer/Sales.Customer as c
  group by c.ID
);
create java action Sales.RetrieveFor<InputType, ResultType>(
  ObjectList: List of InputType not null,
  RetrieveEntity: entity <ResultType> not null
) returns List of ResultType
as $$
return new java.util.ArrayList<>();
$$;
create java action Sales.RetrieveAll<ResultType>(
  RetrieveEntity: entity <ResultType> not null
) returns List of ResultType
as $$
return new java.util.ArrayList<>();
$$;
MDL
mxcli check step1.mdl -p $P --references | tail -1
mxcli -p $P exec step1.mdl | tail -1

# A: two type parameters, entity <ResultType> = a persistent entity
cat > stepA.mdl <<'MDL'
mdl 1;
create microflow Sales.ACT_PersistentResult () returns Integer as $Total
begin
  retrieve $CustomerList from Sales.Customer;
  $OrderList = call java action Sales.RetrieveFor(ObjectList = $CustomerList, RetrieveEntity = 'Sales.Order');
  $Total = sum $OrderList by Amount;
  return $Total;
end;
MDL
echo "--- A"
mxcli check stepA.mdl -p $P --references | tail -1
mxcli -p $P exec stepA.mdl || true

# B: two type parameters, entity <ResultType> = a view entity
cat > stepB.mdl <<'MDL'
mdl 1;
create microflow Sales.ACT_ViewResult () returns Integer as $Total
begin
  retrieve $CustomerList from Sales.Customer;
  $StatsList = call java action Sales.RetrieveFor(ObjectList = $CustomerList, RetrieveEntity = 'Sales.CustomerStats');
  $Total = sum $StatsList by TotalAmount;
  return $Total;
end;
MDL
echo "--- B"
mxcli check stepB.mdl -p $P --references | tail -1
mxcli -p $P exec stepB.mdl || true

# C: one type parameter, only bound through entity <ResultType>
cat > stepC.mdl <<'MDL'
mdl 1;
create microflow Sales.ACT_SingleParam () returns Integer as $Total
begin
  $OrderList = call java action Sales.RetrieveAll(RetrieveEntity = 'Sales.Order');
  $Total = sum $OrderList by Amount;
  return $Total;
end;
MDL
echo "--- C"
mxcli check stepC.mdl -p $P --references | tail -1
mxcli -p $P exec stepC.mdl
mxcli -p $P -c "describe microflow Sales.ACT_SingleParam" | grep "sum "
# D: same call as A, result only read in a loop: exec accepts it, and mx check proves
#    mxbuild types the result as List of Sales.Order
cat > stepD.mdl <<'MDL'
mdl 1;
create microflow Sales.ACT_LoopResult () returns Integer as $Total
begin
  retrieve $CustomerList from Sales.Customer;
  $OrderList = call java action Sales.RetrieveFor(ObjectList = $CustomerList, RetrieveEntity = 'Sales.Order');
  declare $Total Integer = 0;
  loop $IteratorOrder in $OrderList
  begin
    set $Total = $Total + $IteratorOrder/Amount;
  end loop;
  return $Total;
end;
MDL
echo "--- D"
mxcli check stepD.mdl -p $P --references | tail -1
mxcli -p $P exec stepD.mdl

echo "--- mx check"
mxcli docker check -p $P 2>&1 | grep -E "CE[0-9]+|errors" || true

Output (progress lines of mxcli new left out):

Check passed!
Files changed outside the model: 2 (javasource/). Stage them with the .mpr.
--- A
Check passed!
Connected to: Repro/Repro.mpr (Mendix 11.12.7)
Error: microflow 'Sales.ACT_PersistentResult' has validation errors:
  - sum $OrderList by Amount: Sales.Customer has no member "Amount" — it has Name — mxbuild reports this as CE1613 "The selected attribute 'Sales.Customer.Amount' no longer exists"

--- B
Check passed!
Connected to: Repro/Repro.mpr (Mendix 11.12.7)
Error: microflow 'Sales.ACT_ViewResult' has validation errors:
  - sum $StatsList by TotalAmount: Sales.Customer has no member "TotalAmount" — it has Name — mxbuild reports this as CE1613 "The selected attribute 'Sales.Customer.TotalAmount' no longer exists"

--- C
Check passed!
Connected to: Repro/Repro.mpr (Mendix 11.12.7)
Created microflow: Sales.ACT_SingleParam
  $Total = sum $OrderList by ;
--- D
Check passed!
Connected to: Repro/Repro.mpr (Mendix 11.12.7)
Created microflow: Sales.ACT_LoopResult
--- mx check
Checking app for errors...
[error] [CE0015] "Aggregate function must specify a valid attribute." at Aggregate list activity 'Take sum OrderList'
The app contains: 1 errors.

4. Expected output

  • The result type of a Java action call whose return type is List of <T> (or <T>) is the entity passed to the entity <T> parameter: List of Sales.Order in A, C and D, List of Sales.CustomerStats in B. A and B are executed; C is written as sum $OrderList by Amount (describe prints by Amount); mx check reports no errors.
  • Until then: mxcli check --references refuses A and B with the same message as exec, and exec refuses C instead of writing an aggregate without an attribute.

5. Experienced output

Case check --references exec mx check
A: 2 type params, persistent entity Check passed! refused: Sales.Customer has no member "Amount" – (nothing written)
B: 2 type params, view entity Check passed! refused: Sales.Customer has no member "TotalAmount" – (nothing written)
C: 1 type param Check passed! written, but as sum $OrderList by ; CE0015 "Aggregate function must specify a valid attribute."
D: as A, result read in a loop Check passed! written no error: mxbuild types $OrderList as List of Sales.Order

So exec resolves the result type wrongly: with an InputType list argument it takes that list's entity, without one it has no entity at all. mx check (case D) shows the model itself is valid.

Other spellings tried

  • Type parameters in the other order (<ResultType, InputType>) → same refusal: Sales.Customer has no member "Amount"
  • entity <ResultType> parameter declared before the list parameter → same refusal
  • RetrieveEntity = Sales.Order (unquoted) → check passes, same refusal on exec
  • exec --no-check → same refusal (it comes from the microflow validation, not from the pre-flight check)
  • sum $OrderList by Sales.Order.Amount → line 6:34 mismatched input '.' expecting ';'

6. AI bug report

mxcli diag of the repro run:

  Version:     v0.34.0
  Go:          go1.27.4 windows/amd64
  Sessions:    13 (last 7 days)
  Errors:      2 (last 7 days)

Session log of -p Repro/Repro.mpr exec stepA.mdl (from mxcli diag --bundle):

{"time":"2026-11-30T10:30:48.1934766+01:00","level":"INFO","msg":"session_start","version":"v0.34.0","go":"go1.27.4","os":"windows","arch":"amd64","mode":"mxcli exec","args":["mxcli","-p","Repro/Repro.mpr","exec","stepA.mdl"],"pid":11224,"parent_pid":""}
{"time":"2026-11-30T10:30:48.4737008+01:00","level":"ERROR","msg":"execute_error","stmt_type":"CreateMicroflowStmt","stmt_summary":"create microflow Sales.ACT_PersistentResult","error":"microflow 'Sales.ACT_PersistentResult' has validation errors:\n  - sum $OrderList by Amount: Sales.Customer has no member \"Amount\" — it has Name — mxbuild reports this as CE1613 \"The selected attribute 'Sales.Customer.Amount' no longer exists\"\n","duration_ms":5}

The log shows exec refusing case A with the wrong result type; check on the same script passed (repro output above).

Why it matters

Generic Java actions that take an entity parameter to decide their result type ("retrieve objects of entity X over an association for this list") are a common pattern for bulk retrieves. An aggregate over their result is refused by exec (after check passed), or silently written without an attribute. Workaround: retrieve the result entity again with a plain retrieve, or only read the result inside a loop (case D).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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