-3
javax.faces.FacesException: #{scheduleBean.insert()}: java.util.ConcurrentModificationException
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: javax.faces.el.EvaluationException: java.util.ConcurrentModificationException

Code:

 public void insert(){

       for(ScheduleMaster v:arrayList1){

           arrayList1.add(mm.i, v); 
       }           
       List<ScheduleMaster>temp1=new ArrayList<ScheduleMaster>();
       temp1=arrayList1;
       System.out.println("Coming Insert");
       Iterator<ScheduleMaster>itr=temp1.iterator();
         while(itr.hasNext()){
             ScheduleMaster s=itr.next();
             s.setServiceCode(serviceCode);
             s.setServiceName(serviceName);
             s.setVessalCode(vessalCode);
             s.setVessalName(vessalName);
             s.setVoyage(voyage);
             s.setPortCode(portCode);
             s.setPortName(portName);
             s.setTerminalCode(terminalCode);
             s.setTerminalName(terminalName);
             s.setEta(eta);
             s.setEtaTimes(etaTimes);
             s.setEtd(etd);
             s.setEtdTimes(etdTimes);
             s.setBound(bound);
             s.setAta(ata);
             s.setAtaTimes(ataTimes);
             s.setAtd(atd);
             s.setAtdTimes(atdTimes);
             arrayList1.add(s);                        

       } 

   }    
1
  • 1
    This is not a well defined question, only a stacktrace and a code snippet. And also it seems a duplicate question. Commented Aug 12, 2015 at 7:53

1 Answer 1

2

temp1 and arrayList1 is the reference to the same object. And you cannot iterate over an object and change it while iteration.

So you have to clone the object and then you can iterate over the clone and change the original.

  List<ScheduleMaster>temp1=new ArrayList<ScheduleMaster>();
  for(ScheduleMaster v:arrayList1){

       arrayList1.add(mm.i, v); 
       temp1.add(mm.i, v); 
   }           
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.