commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maleven (JIRA)" <>
Subject [jira] [Created] (COLLECTIONS-595) ListOrderedSet remove()
Date Sun, 25 Sep 2016 21:09:20 GMT
Maleven created COLLECTIONS-595:

             Summary: ListOrderedSet remove()
                 Key: COLLECTIONS-595
             Project: Commons Collections
          Issue Type: Bug
          Components: Set
    Affects Versions: 4.1
         Environment: Windows 10, Eclipse Neon Release (4.6.0)
            Reporter: Maleven

Hello Apache,

I have a class which overrides equals() and hasCode().
I create a ListOrderedSet<MyClass> mySet= new ListOrderedSet<MyClass>(), and add
objects to it:

Each object is initialized in the constructor with two properties first. The other properties
are set afterwards, when
they are already contained in the ListOrderedSet. After I change/add some properties, then
if I do mySet.contains(obj1), false is returned.
I read about that when a hashmap is created with the objects inside and then changing the
objects inside it does not change
the hasmap's internal hashcode for the objects or something like that.

These properties are found in the equals and hashcode. (When not there is no issue.).

The following happens. If I still want to remove an object which was changed afterwards, in
the method: public E remove(final int index),
inside public E remove(final int index) false is returned. But the object is still removed
and in the debugger the following can be seen:

DEBUG Info: == 5 (internal HashMap)
this.collections.setOrder.size == 4. (internal ArrayList)

Afterwards if I print the list with the overrided toString() method IndexOutOfBoundsException
is thrown when getting the size of mySet
via mySet.size(), but not when I use an iterator to count the objects in the set.

    public int getSize() {
    	OrderedIterator it = mySet.iterator();
    	int i = 0;
//if i return i then the items are 4, when returning memorySet.size(), the items are 5.
//    	return i;
        return mySet.size();


    public String toString() {

        String toReturn = "\n";

        for (int i = 0; i < getSize(); i++) {

            toReturn = toReturn + mySet.get(i) + "\n";

        return toReturn;

So my question is: is this a bug or is it because of my changing/updating the objects in the
list, and why if it returns false when removing it got deleted anyway?
Should it not got deleted to start with? 

Thank you for your effort.

P.S. I am a self taught programmer. It's my first time sending a bug issue, maybe it's a bit
long or I did not send with it other information I should have.

This message was sent by Atlassian JIRA

View raw message