Share

TriActive Java Data Objects (TJDO)

Tracker: Bugs

5 Set.remove always returns true? - ID: 634261
Last Update: Comment added ( jackknifebarber )

I think I've found a bug with Set.remove.

I tried to remove an element from a persistent set (not
an inverse set) that was not in that set. I expected the
Set.remove() method tro return false, it returned true
thus breaking the contract of the Set interface.

I tried to find the code and I think it is in...

AbstractSetStore.remove(StateManager sm, Object
element)

Looking at the code, the following lines lead me to think
it will return true even if the element did not exists in the
set...

ps.executeUpdate();

if (LOG.isDebugEnabled())
LOG.debug("Time = " +
(System.currentTimeMillis() - startTime) + " ms: " +
removeStmt);

modified = true;


This does not check the number of rows by the query
and so cannot know if there was a row to delet or not.

Would something like this do the job...

int deleteCount = ps.executeUpdate();

if (LOG.isDebugEnabled())
LOG.debug("Time = " +
(System.currentTimeMillis() - startTime) + " ms: " +
removeStmt);

modified = deleteCount == 1;

Maybe an assertion that deleteCount is < 1 would be
good too.

I couldn't find the unit test for this so don;t know if it has
been tested.

Matty.


Matthew Cooper ( matthewcooper ) - 2002-11-06 05:37

5

Closed

Fixed

Mike Martin

Core

v2.0 Beta

Public


Comment ( 1 )

Date: 2002-12-07 07:24
Sender: jackknifebarberProject Admin

Logged In: YES
user_id=582193

Applied. A test has been added for Set.remove() as well.

Thanks,

Mike


Attached File

No Files Currently Attached

Changes ( 4 )

Field Old Value Date By
status_id Open 2002-12-07 07:24 jackknifebarber
resolution_id None 2002-12-07 07:24 jackknifebarber
assigned_to nobody 2002-12-07 07:24 jackknifebarber
close_date - 2002-12-07 07:24 jackknifebarber