I am getting an concurrent modification error while editing an XML file using Java in a JSP file. How is this caused and how can I solve it?
ElementFilter f = new ElementFilter("rurl-link");
Iterator subchilditr = childNode.getDescendants(f);
while (subchilditr.hasNext()) { // Exception is thrown here.
Element subchild = (Element) subchilditr.next();
if (subchild.getText().equalsIgnoreCase(prevtext)) {
subchild.setText(link);
out.println("Updated");
}
}
This is the stacktrace:
java.util.ConcurrentModificationException
java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
java.util.AbstractList$Itr.next(AbstractList.java:343)
org.jdom.DescendantIterator.next(DescendantIterator.java:134)
org.jdom.FilterIterator.hasNext(FilterIterator.java:91)
org.apache.jsp.rurl_005fchangelink_005fxml_jsp._jspService(rurl_005fchangelink_005fxml_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)