[jboss-jira] [JBoss JIRA] Resolved: (JBRULES-1588) collect fails when using treeset

Edson Tirelli (JIRA) jira-events at lists.jboss.org
Fri May 2 08:47:29 EDT 2008


     [ http://jira.jboss.com/jira/browse/JBRULES-1588?page=all ]

Edson Tirelli resolved JBRULES-1588.
------------------------------------

    Fix Version/s:     (was: 5.0.0-M1)
                       (was: 4.0.7)
       Resolution: Rejected

This problem is cause by the wrong implementation in the fact class of the "Comparable" interface.

A simple test shows you the problem with your implementation. If you look at your Message.compareTo() method, you have this:

        public int compareTo(Object o) {
            return -1;
        }

That is clearly wrong. Simply doing this will show you the problem:

            TreeSet set = new TreeSet();
            set.add( message1 );
            set.add( message2 );
            
            System.out.println(set);       
            System.out.println( set.remove( message2 ) );
            System.out.println( set );

Console output:

[[Hello World1], [Hello World]]
false
[[Hello World1], [Hello World]]

Implementing the compare to method correctly makes everything work:

        public int compareTo(Object o) {
            return getMessage().compareTo( ((Message)o).getMessage() );
        }

Please note that the compareTo() method is using getXXX() methods to access the attributes, since shadow proxies will required and they are proxies.
A slight change in your rule:

 rule "Retract From TreeSet"
	when
	    $tree: TreeSet( size > 0 ) from collect (Message()  )
	then
	System.out.println($tree);
	retract($tree.first());
end

And the run result is:

[[Hello World], [Hello World1]]
[[Hello World1]]



> collect fails when using treeset
> --------------------------------
>
>                 Key: JBRULES-1588
>                 URL: http://jira.jboss.com/jira/browse/JBRULES-1588
>             Project: JBoss Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>    Affects Versions: 4.0.6
>            Reporter: pchar
>         Assigned To: Edson Tirelli
>         Attachments: treemap.zip
>
>
> Hi All,
> i've a simple rules that retract objects form the WM
>  rule "Retract From TreeSet"
> 	when
> 	$tree: TreeSet() from collect (Message()  )
> 	then
> 	System.out.println($tree.first());
> 	retract($tree.first());
> end
> after the firts run the following exception is thrown
> org.drools.FactException: Retract error: handle not found for object: [Hello World]. Is it in the working memory?
> [Hello World]
> 	at org.drools.base.DefaultKnowledgeHelper.retract(DefaultKnowledgeHelper.java:120)
> 	at com.sample.Rule_Retract_From_TreeSet_0.consequence(Rule_Retract_From_TreeSet_0.java:9)
> 	at com.sample.Rule_Retract_From_TreeSet_0ConsequenceInvoker.evaluate(Rule_Retract_From_TreeSet_0ConsequenceInvoker.java:22)
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
> 	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
> 	at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:471)
> 	at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
> 	at com.sample.DroolsTest.main(DroolsTest.java:36)
> org.drools.spi.ConsequenceException: org.drools.FactException: Retract error: handle not found for object: [Hello World]. Is it in the working memory?
> 	at org.drools.base.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:14)
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
> 	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
> 	at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:471)
> 	at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
> 	at com.sample.DroolsTest.main(DroolsTest.java:36)
> Caused by: org.drools.FactException: Retract error: handle not found for object: [Hello World]. Is it in the working memory?
> 	at org.drools.base.DefaultKnowledgeHelper.retract(DefaultKnowledgeHelper.java:120)
> 	at com.sample.Rule_Retract_From_TreeSet_0.consequence(Rule_Retract_From_TreeSet_0.java:9)
> 	at com.sample.Rule_Retract_From_TreeSet_0ConsequenceInvoker.evaluate(Rule_Retract_From_TreeSet_0ConsequenceInvoker.java:22)
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
> 	... 4 more

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list