[ 
https://issues.apache.org/jira/browse/COLLECTIONS-595?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Bruno P. Kinoshita resolved COLLECTIONS-595.
--------------------------------------------
    Resolution: Not A Bug

> ListOrderedSet remove()
> -----------------------
>
>                 Key: COLLECTIONS-595
>                 URL: https://issues.apache.org/jira/browse/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 hashCode().
> I create a ListOrderedSet<MyClass> mySet= new ListOrderedSet<MyClass>(), and 
> add objects to it:
> mySet.add(obj1);
> etc.
> 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:
> this.collections.map.size == 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.
> {code:java}
>     public int getSize() {
>       
>       OrderedIterator it = mySet.iterator();
>       int i = 0;
>       while(it.hasNext()){
>               
>               it.next();
>               i++;
>               
>       }
> //if i return i then the items are 4, when returning memorySet.size(), the 
> items are 5.
> //            return i;
>         return mySet.size();
>     }
>     @Override
>     public String toString() {
>         String toReturn = "\n";
>  
>         for (int i = 0; i < getSize(); i++) {
>             toReturn = toReturn + mySet.get(i) + "\n";
>         }
>         return toReturn;
>     }
> {code}
> 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
(v6.3.15#6346)

Reply via email to