You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris <ch...@gmx.at> on 2015/02/06 17:56:06 UTC

Sortable - ConcurrentModificationException

Hi Sebastian,

I am using the method #ListUtils.move to sort a list of domain objects as soon as the method #onUpdate is called within a sortable object:
In the first request, everything is fine, but in the second request I am receiving following error:
Root cause:

java.util.ConcurrentModificationException
     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
     at java.util.ArrayList$Itr.next(ArrayList.java:851)

Can you give me a hint why this error occurs and how to fix it?

@Override
public void onUpdate(AjaxRequestTarget target, String item, int index) {
    super.onUpdate(target, item, index);
    user.sortObj(item, index);

}
*****************************
Class User:
private final List<Item> selectedItems = Lists.newArrayList();
public void sortItems(String itemName, int index) {
    for (Item currentItem : selectedItems) {
      if (itemName.equals(currentItem.getName())) {
          ListUtils.move(currentItem, index, selectedItems);
      }
    }
}

Thanks a lot,
Chris


Re: Sortable - ConcurrentModificationException

Posted by Sebastien <se...@gmail.com>.
Hi Chris,

Right, you probably you can use an iterator instead of the "foreach"
statement...
Thanks for letting know you solved it! :)

Best regards,
Sebastien.

On Fri, Feb 6, 2015 at 6:05 PM, Chris <ch...@gmx.at> wrote:

> I have fixed it - it was because of calling the method within the for loop.
>
> br, Chris
>
>
>
> > Am 06.02.2015 um 17:56 schrieb Chris <ch...@gmx.at>:
> >
> > Hi Sebastian,
> >
> > I am using the method #ListUtils.move to sort a list of domain objects
> as soon as the method #onUpdate is called within a sortable object:
> > In the first request, everything is fine, but in the second request I am
> receiving following error:
> > Root cause:
> >
> > java.util.ConcurrentModificationException
> >     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
> >     at java.util.ArrayList$Itr.next(ArrayList.java:851)
> >
> > Can you give me a hint why this error occurs and how to fix it?
> >
> > @Override
> > public void onUpdate(AjaxRequestTarget target, String item, int index) {
> >    super.onUpdate(target, item, index);
> >    user.sortObj(item, index);
> >
> > }
> > *****************************
> > Class User:
> > private final List<Item> selectedItems = Lists.newArrayList();
> > public void sortItems(String itemName, int index) {
> >    for (Item currentItem : selectedItems) {
> >      if (itemName.equals(currentItem.getName())) {
> >          ListUtils.move(currentItem, index, selectedItems);
> >      }
> >    }
> > }
> >
> > Thanks a lot,
> > Chris
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Sortable - ConcurrentModificationException

Posted by Chris <ch...@gmx.at>.
I have fixed it - it was because of calling the method within the for loop.

br, Chris



> Am 06.02.2015 um 17:56 schrieb Chris <ch...@gmx.at>:
> 
> Hi Sebastian,
> 
> I am using the method #ListUtils.move to sort a list of domain objects as soon as the method #onUpdate is called within a sortable object:
> In the first request, everything is fine, but in the second request I am receiving following error:
> Root cause:
> 
> java.util.ConcurrentModificationException
>     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
>     at java.util.ArrayList$Itr.next(ArrayList.java:851)
> 
> Can you give me a hint why this error occurs and how to fix it?
> 
> @Override
> public void onUpdate(AjaxRequestTarget target, String item, int index) {
>    super.onUpdate(target, item, index);
>    user.sortObj(item, index);
> 
> }
> *****************************
> Class User:
> private final List<Item> selectedItems = Lists.newArrayList();
> public void sortItems(String itemName, int index) {
>    for (Item currentItem : selectedItems) {
>      if (itemName.equals(currentItem.getName())) {
>          ListUtils.move(currentItem, index, selectedItems);
>      }
>    }
> }
> 
> Thanks a lot,
> Chris
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org