Is it possible for this state to exist in PersistentSet?
Code:
false == values.contains( values.iterator().next() );
Because I am getting this state for some reason. A have a Set where I remove a bunch of values. All of them get removed except for one. I don't know why and I can't narrow it down to something reproducible. In other test cases this works fine but I have a particular test case where all but one item is successfully removed.
The odd part is for the item that could not be removed that if I iterate through the set it shows one element, and in fact it reports a size of 1. But if I ask the set if it contains the value it says "no". Oh, and the statement "values.remove( value )" returns FALSE even though I can see that value in the PersistentSet entries.
Any thoughts?
BTW, this uses an ElementCollection in the entity with a Set of an embeddable class. If I do this, it works:
Code:
Set<MyValue> values = new HashSet<>( entity.getValues() );
for ( Iterator<MyValue> it = candidates.iterator(); it.hasNext(); ) {
MyValue value = it.next();
if ( shouldDelete( value ) ) {
Asserts.that( values.contains( value ), "Huh?" );
it.remove();
}
}
entity.setValues( values );
However, if I remove the new HashSet creation and use the values Set directly and remove the line "entity.setValues" I will get "Huh?" printed out at some point. When I look in the debugger, the value that the set lost track of seems to be the very first entry in the backing HashSet. But the set doesn't think its there even though it is.