0

Hi I want to know what's wrong with my code, I am having a concurrentexception, and I assume this lines cause it, but i don't know which specific part. Thanks in advance

The exception is shown below and the codes that the exception is pointing, I really dont know what causes the concurrent problem. thanks a lot for helping!

java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextNode(HashMap.java:1437)
    at java.util.HashMap$KeyIterator.next(HashMap.java:1461)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionManager.findListeners(InfinispanSessionManager.java:321)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionManager.triggerPrePassivationEvents(InfinispanSessionManager.java:298)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionManager$SchedulableSession.close(InfinispanSessionManager.java:375)
    at org.wildfly.clustering.web.undertow.session.DistributableSession.requestDone(DistributableSession.java:71)
    at io.undertow.servlet.spec.ServletContextImpl.updateSessionAccessTime(ServletContextImpl.java:730)
    at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:578)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:308)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
  • Possible duplicate of [How to avoid java.util.ConcurrentModificationException when iterating through and removing elements from an ArrayList](https://stackoverflow.com/questions/8104692/how-to-avoid-java-util-concurrentmodificationexception-when-iterating-through-an) – Siguza Nov 08 '18 at 03:49
  • 1
    That exception is telling you that you can't modify the thing you are iterating over while you're iterating over it. – Katie.Sun Nov 08 '18 at 03:51
  • may be I am missing something but the code is iterating over `xForwardedFor` but the thing being updated is `XForwardedForStr`.. so @Siguza and @Katie.Sun, may be your comments are not relevant? – Kartik Nov 08 '18 at 03:58
  • @Warren please post the error trace and what type is `xForwardedFor` – Kartik Nov 08 '18 at 03:59
  • You should folliw the Java Naming Conventions: variable names start with lowercase. – MC Emperor Nov 08 '18 at 07:52
  • i added the exception and the the whole method thanks guys – Warren Gonzales Nov 12 '18 at 06:47
  • Hmm... This looks like it is not coming from your code, but from the session manager of your servlet container. – Thilo Nov 16 '18 at 08:59

2 Answers2

2

This looks to be a bug in Wildfly that has been fixed in recent releases.

Try to update to the latest version if you can, I don't think there is much you can do about it in your code.

Thilo
  • 257,207
  • 101
  • 511
  • 656
-1

If you need to modify items in your collection, use Iterator instead of loops