[rules-dev] Cloning Collections issue

Mark Proctor mproctor at codehaus.org
Thu May 26 00:44:07 EDT 2011


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?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20110526/19ae0492/attachment.html 


More information about the rules-dev mailing list