[jboss-jira] [JBoss JIRA] Commented: (JBRULES-2057) Collection returned by StatefulKnowledgeSession.getObjects() doesn't conform to standard collection behaviour
Damon Horrell (JIRA)
jira-events at lists.jboss.org
Wed May 13 18:04:57 EDT 2009
[ https://jira.jboss.org/jira/browse/JBRULES-2057?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12467385#action_12467385 ]
Damon Horrell commented on JBRULES-2057:
----------------------------------------
What I was trying to do is determine whether or not an object (equality not identity) is in the working memory and fetch it if it is. I don't have the exact identical object so I construct a new object with the necessary attributes to satisfy the equals method, and then I expected to be able to go:
StatefulKnowledgeSession.getObjects().contains(x)
but instead have to use:
new ArrayList(StatefulKnowledgeSession.getObjects()).contains(x)
The workaround is easy so it's not a big deal, but this is non-standard behaviour for a collection implementation.
Can you not just change the implementation of ObjectStoreWrapper.contains so that it checks all objects in working memory to see if one equals the specified one, rather than only checking if it contains this specific instance? I guess there is a performance hit with this which would matter if this method is used heavily internally.
> Collection returned by StatefulKnowledgeSession.getObjects() doesn't conform to standard collection behaviour
> -------------------------------------------------------------------------------------------------------------
>
> Key: JBRULES-2057
> URL: https://jira.jboss.org/jira/browse/JBRULES-2057
> Project: JBoss Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 5.0.0.CR1
> Reporter: Damon Horrell
> Assignee: Mark Proctor
> Attachments: drools-bug-tests.zip
>
>
> StatefulKnowledgeSession.getObjects() returns a collection containing the objects in working memory.
> The Javadoc for Collection.contains says:
> "Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)). "
> This is not the case though for StatefulKnowledgeSessionImpl.ObjectStoreWrapper. The implementation of contains returns true only if it is the exact same object instance, but false if it is a different instance but which equals the instance in the working memory.
> A workaround is to create a new collection and put the items returned into that.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list