https://issues.jboss.org/browse/JBRULES-3051
Previously ALL collections where cloned when bound:
public Object getNonShadowedValue(InternalWorkingMemory workingMemory,
final Object object) {
Object result =this.readAccessor.getValue( workingMemory,
object );
if (this.isInternalFact()&& resultinstanceof Collection ) {
try {
Collection newCol = (Collection) result.getClass().newInstance();
for ( Iterator it = ((Collection) result).iterator(); it.hasNext(); ) {
Object element = it.next();
newCol.add( element );
}
return newCol;
}catch ( InstantiationException e ) {
// nothing we cando, so justreturn the resulting object
}catch ( IllegalAccessException e ) {
// TODO Auto-generatedcatch block
}
}
return result;
}
This was left over from shadow facts and actually still existed today. I
have removed the code but now we have a failing test in
FirstOrderLogicTest.testCollectResultConstraints.
rule"Collect Test" salience 70
when
$cheeseList : ArrayList(size == 1) from collect( Cheese( ) );
then
results.add($cheeseList);
end
The reason why this passed before was the collection was cloned, so the
accumulate's evaulations would not impact it. Now it is no longer cloned
and while the rule does not fire the Collection is updated. I think the
later is the correct behaviour and I've updated the test as expected.
Everyone agreed?