Issue Details (XML | Word | Printable)

Key: NUCCORE-543
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Areg Beketovski
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus Core

List.contains() returns inconsistent/incorrect result for a non-persistent argument

Created: 09/Jun/10 03:53 PM   Updated: 04/Oct/12 05:02 PM
Component/s: None
Affects Version/s: 2.1.0.m3
Fix Version/s: None

File Attachments: 1. Text File List.patch (0.5 kB)
2. Zip Archive (4 kB)
3. Zip Archive (3 kB)

Datastore: Microsoft SQL Server, MySQL

 Description  « Hide
Class A has a field "List<B> items". Class B has field "double value" and equals overridden to take into account the value of "value" (sorry for tautology :-)). An instance of B is added to A.items and A's instance is persisted. After retrieving A's instance back from the datastore and running contains() on the new instance of B with the same "double value" it returns "false". After iterating A.items it returns true for contains() with the same argument.

Looks like for the first time the cache is not loaded, so the is used and ElementContainerStore.validateElementForReading() returns false, as the "element" is not persistent and not detached (it was never persisted). Not sure if this should be taken into account as it breaks transparency of JDO - if two objects are equal in Java terms why are they considered different if they differ in an opaque "persistent" state.

The second time already cached java.util.ArrayList collection is used, returning correct result.

Please see the attached testcase.

Areg Beketovski made changes - 09/Jun/10 03:54 PM
Field Original Value New Value
Attachment [ 11202 ]
Areg Beketovski added a comment - 09/Jun/10 06:07 PM
Verified java.util.List docs just in case:


Returns true if this list contains the specified element.
More formally, returns true if and only if this list contains
at least one element e such that

boolean contains(Object o)

Areg Beketovski added a comment - 10/Jun/10 12:36 PM
Suggested patch, that partially fixes the problem.

With or without this patch List.contains() returns false always for non-persistent argument when "datanucleus.cache.collections=false".

Areg Beketovski made changes - 10/Jun/10 12:36 PM
Attachment List.patch [ 11212 ]
Andy Jefferson added a comment - 13/Oct/11 12:55 PM
See also NUCCORE-684, merged into this since the same thing

Andy Jefferson made changes - 13/Oct/11 12:55 PM
Attachment [ 11512 ]
Andy Jefferson added a comment - 10/Mar/12 09:09 AM
Downgrading since the issue is use of methods only present in instances, so they have to be instantiated to evaluate them, hence you have to cache the collection. i.e easy workaround

Andy Jefferson made changes - 10/Mar/12 09:09 AM
Priority Major [ 3 ] Minor [ 4 ]
Andy Jefferson made changes - 04/Oct/12 05:02 PM
Component/s JDO [ 10201 ]