Thebas opened a new issue, #7239:
URL: https://github.com/apache/incubator-kie/issues/7239
**Executable model: `from collect` into a concrete collection class collects
SubnetworkTuples instead of facts**
### Description
With the executable model, when the target of `from collect` is a concrete
collection class (for example `ArrayList`) and the collected pattern runs in a
subnetwork (for example it has an inner `from`), the collected collection
contains `org.drools.core.reteoo.SubnetworkTuple` instances instead of the
matched facts.
Effects:
- Reading elements of the list throws `ClassCastException`, and equality
checks against facts fail. `size()` is still correct.
- Marshalling the session with `SerializablePlaceholderResolverStrategy`
fails with `java.io.NotSerializableException:
org.drools.core.reteoo.AccumulateNode$AccumulateContext`, because the collected
list (the accumulate result) is serialized together with the tuples.
The classic DRL engine is not affected, and neither are `List`, `Collection`
or `Set` targets in the executable model.
### Reproducer
```
rule R when
$p: Person()
$list: ArrayList() from collect (
Address() from $p.addresses
)
then
result.addAll($list);
end
```
Insert a `Person` with two `Address` objects and fire the rules. With
`PATTERN_DSL`, `result` holds two `SubnetworkTuple` objects. With
`STANDARD_FROM_DRL`, it holds the two addresses. Marshalling the session
afterwards fails only with the executable model.
### Cause
`GenericCollectAccumulator.accumulate` (drools-model-compiler) adds
`handle.getObject()` to the collection without unwrapping a `SubnetworkTuple`.
`CollectAccumulator` (classic engine) and `LambdaAccumulator.NotBindingAcc`
(used for `List`/`Collection`/`Set` targets) both unwrap it.
`GenericCollectAccumulator` was introduced in DROOLS-7534 (#5493).
### Proposed fix
```java
Object value = handle.getObject();
if (value instanceof SubnetworkTuple) {
value = ( (SubnetworkTuple) value ).getFactHandle().getObject();
}
((Collection) context).add( value );
return value;
```
This matches `CollectAccumulator`. With it, a codegen test (list contents)
and a test-compiler-integration test (marshalling round trip) pass in both
engine modes, and the drools-model-compiler and drools-model-codegen test
suites pass.
### Workaround
Declare the target as `List()` or `Collection()` instead of a concrete class.
--
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]