• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.ConcurrentModificationException  RSS feed

 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Can anyone explain where i am doing it wrong in this code and how to remediate it? I want to remove 'second' entry and add 'fourth' entry.

I have the following error:

java.util.ConcurrentModificationException
java.util.ArrayList$Itr.checkForComodification(ArrayList.java:886)
java.util.ArrayList$Itr.next(ArrayList.java:836)
org.apache.jsp.alg3.nytest_jsp._jspService(nytest_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides using a scriptlet?
The for-each loop construct in your code uses an Iterator behind the scenes. If you modify the list by any means other than via that Iterator a ConcurrentModificationException will be thrown.
Thing is, you can't get at the Iterator used by the for-each loop, so you'll either need to get one explicitly using the List's iterator() method and use that one to loop and remove items, or use a good old for-loop and remove the items by their index.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It amazes me that anyone writes scriptlets in JSPs in 2014. For any reason; "it's just test code", "it's just a prototype", "it's for learning", are all inadequate at this point.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,
this is just for testing purpose. The java code will go inside a class. I thought it would be better if someone can just copy the code and test it to see the error.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelle,
Thanks for your explanation. All is right now.
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Ngom wrote:Bear,
this is just for testing purpose. The java code will go inside a class. I thought it would be better if someone can just copy the code and test it to see the error.


But that's completely backwards. A JSP is one of the worst possible environments for testing Java code. It would be just as easy to write a small Java class to do that little test, actually even easier because you could just run the thing instead of having to run a server and send it a request to run the JSP.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A JSP is one of the worst possible environments for testing Java code.

Ok, Paul.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Ngom wrote:this is just for testing purpose.

As I said:
Bear Bibeault wrote:For any reason; "it's just test code", ... are all inadequate at this point.

And this could not be more true:
Paul Clapham wrote:But that's completely backwards. A JSP is one of the worst possible environments for testing Java code.

I advise learning how to test code for real. We have a testing forum full of great info.

 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I advise learning how to test code for real. We have a testing forum full of great info.

Hi Bear,
Can you give me a link to that forum, please? I could not find it on the website.
Kind regards
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the first one listed in the "Engineering" section.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Ulf. I thought you hosted a test server where one could upload a java application and test it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!