-1

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.

tokhi
  • 19,860
  • 23
  • 91
  • 104

2 Answers2

1

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)

Christian Kuetbach
  • 15,550
  • 4
  • 42
  • 78
0

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.

Skyost
  • 1,161
  • 1
  • 12
  • 29