0

Expand all / collapse all causing ConcurrentModificationException

asked 2020-02-18 01:39:03 +0800

vsriram92 gravatar image vsriram92
33 3

updated 2020-02-18 14:59:54 +0800

I have a custom group model created for my project. Code available at https://zkfiddle.org/sample/nb4hk2/2-CustomGroupsModel-expand-collapse-all

Issue : Group Expand all / collapse all causing ConcurrentModificationException

Steps: Click collapse all button in the fiddle.

Expected Result - All groups should collapse

Actual Result - Only the 1st group is getting collapsed. Getting ConcurrentModificationException.

After collapsing all groups manually, clicking Expand all button also gives same exception.

Note: The code I use is evolved from https://forum.zkoss.org/question/112061/group-open-not-working-for-custom-group-model/

I'm not sure whether it is a bug or I'm missing something?

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-02-18 16:47:27 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

Hi vsriram92,

It's counter-intuitive, but you cannot change the children of the listbox while iterating over listbox children, or the "next" statement becomes meaningless. Closing groups cause the listbox to drop children of closed groups, opening groups cause the listbox to generate new children in these groups.

As such, you are in a situation where you are modifying the collection (by opening or closing groups) while iterating into the same collection.

A way to avoid that is to build your change list, then do all changes after reading all children, or to just go over the groups collection (which doesn't change when opening or closing a group).

private void expandCollapseAll(Component view, boolean toExpand){ Listbox listBox = (Listbox) view.getFellowIfAny("processList"); List<listgroup> groups = listBox.getGroups(); for (Listgroup listgroup : groups) { listGroupExpandCollapse(listgroup, toExpand); } notifyCollapseButton(!toExpand); }

see the modified fiddle here: https://zkfiddle.org/sample/nb4hk2/3-CustomGroupsModel-expand-collapse-all

link publish delete flag offensive edit

Comments

The key here is that Listbox children are not a 1:1 reflexion of the GroupsModel data.

MDuchemin ( 2020-02-18 16:48:18 +0800 )edit

If a group is closed, then the listbox doesn't have children under that group as listitem. As such, the number of children of the listbox changes everytime you open or close a group, while the number of entries int he GroupsModel stays the same

MDuchemin ( 2020-02-18 16:49:18 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-02-18 01:39:03 +0800

Seen: 6 times

Last updated: Feb 18 '20

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More