hwu2024 opened a new issue, #6472:
URL: https://github.com/apache/incubator-kie-drools/issues/6472
### Summary
In the exec-model code generator, the set of “used declarations” for a rule
consequence is collected and then iterated to (1) build `D.on(...)` and (2)
build parameters for the generated `LambdaConsequence…` (`BlockN<…>`). Because
this was done via an unordered collection, iteration order could vary across
environments. When the two iterations disagree, the generated `BlockN<…>`
signature no longer matches the `D.on(...)` argument order, causing a
compile-time error in generated sources.
**Modules:** `drools-model/drools-model-codegen`
**Area:** Exec-model code generation (consequences / `D.on(...)` and
`LambdaConsequence...`)
**Relates to:** Nondeterministic order exposed by
`TypeCoercionTest#testComparisonCoercion`
### Steps to Reproduce
Running the test normally:
```bash
mvn -pl drools-model/drools-model-codegen \
test
-Dtest=org.drools.model.codegen.execmodel.TypeCoercionTest#testComparisonCoercion
```
passes. However, the same test fails when executed under the NonDex plugin,
which perturbs the iteration order of non-deterministic Java collections:
```bash
mvn -pl drools-model/drools-model-codegen \
edu.illinois:nondex-maven-plugin:2.1.7:nondex \
-Dtest=org.drools.model.codegen.execmodel.TypeCoercionTest#testComparisonCoercion
```
The failure is a compile-time error in generated sources:
```
The method execute(Block2<String,List<String>>) in the type
ConsequenceBuilder._2<String,List<String>>
is not applicable for the arguments (LambdaConsequence…)
```
It indicates a mismatch between the order expected by
`ConsequenceBuilder._N<...>.execute(...)` (as implied by `D.on(var_A, var_B,
...)`) and the functional type implemented by the generated lambda
(`LambdaConsequence…`).
### Root Cause
Use of unordered `Set` collection(s) (e.g., via `Collectors.toSet()`) during
consequence generation. Java’s `HashSet` does not guarantee iteration order;
`Collectors.toSet()` is unordered.
### Fixes
I am currently working on the fixes and will later provide a PR related to
this issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]