Question

I have a servlet which uses a service to parse a YAML file. but when I put some user traffic on my servlet I get:

SEVERE: Servlet.service() for servlet [SitesController] in context with path [] threw exception [java.util.ConcurrentModificationException] with root cause
java.util.ConcurrentModificationException
    at java.util.ArrayList$SubList.checkForComodification(ArrayList.java:1129)
    at java.util.ArrayList$SubList.listIterator(ArrayList.java:1009)
    ...
    at com.example.UrlRedirectEngin.redirectoToRespectiveSubDomain(UrlRedirectEngin.java:250)

I am not sure if the exception is from parsing the YAML file or not. However the exception is pointing to the line below which I render the page line 250:

request.getRequestDispatcher(JSP_PAGE).forward(request, response);

I just want to know if ConcurrentModificationException can also happens while adding elements to a Map? If yes how can I handle this issue. Thanks.

Was it helpful?

Solution

The line

request.getRequestDispatcher(JSP_PAGE).forward(request, response);

forwards to an JSP page. The error may be inside of that JSP as well (the part of the stacktrace may hide the original error)

OTHER TIPS

ConcurrentModificationException means that you are editing your map/collection when you try to read it. Simple example :

final List<String> list = new ArrayList<String>()
    private static final long serialVersionUID = 1L; {
        {
            add("Hi");
            add("This is a test");
        }
    };
for(final String string : list) {
    if(string.equals("Hi")) {
        list.remove("Hi");
    }
}

I think getRequestDispatcher is modifying your map while your using it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top