I have the following error:
Exception in thread "Thread-0" java.util.ConcurrentModificationException
at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1584)
at java.base/java.util.HashMap$KeyIterator.next(HashMap.java:1607)
at Server$1.run(Server.java:149)
at java.base/java.lang.Thread.run(Thread.java:832)
Reffering to this code:
    for (Session key : sessions.keySet()) {
                        if (key.getPort2() != port && key.getPort1() != port) { // change later to ip
                            System.out.println("2nd time init 2 client");
                            session.setIp2(ip);
                            session.setPort2(port);
                            sessionID++;
                            sessions.put(session, sessionID);
                            // reset session
                            session = null;
                        }
                    }
Could you explain why this happens?
 
     
    