Error : java.util.ConcurrentModificationException

痞子三分冷 提交于 2019-11-29 17:36:45

The exception stack trace points to the s:iterator in your jsp being the place where the exception is thrown. That means that while that element goes through the book list another piece of code adds or removes from the list. That could be your Java code, or some other (e.g. RemovebooksFromSession).

Take a look at your code and try to determine if it is possible that other code runs while your jsp page is being build.

Cannot help you more with the code you posted.

Fundamentally, you're modifying an object while some other object is depending on the state of the first object to remain unchanged.

This is most often seen when using a non-modification-safe iterator on some sort of collection object, and then modifying the collection.

My JSP is too rusty to wade through your source, but I see a couple of cases where you appear to be using iterators, and the one in your JSP looks most suspect.

(I believe this error can also occur when you use multi-threading to manage collection objects in a non-thread-safe fashion.)

It is possible that the page is refreshed around the time your code executes "books.add(book);" in which case you will get the exception as you are modifying a collection at same time someone else is using it.

Is it possible to modify your code so that the "books" you modify in the AddBookToSession is copy of the internal list of books.

books = new ArrayList<Bookdetails>((ArrayList) session.get(BillTransactionBooksConstants.BOK););
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!