I have written following code which is resulting in concurrent modification exception. How can I prevent it ? The idea is to escape all values of the Map and reconstruct the object (dO) back with new param map.
try {
Map<String,String[]> paramMap = dO.getParameterMap();
Set<Map.Entry<String, String[]>> entries = paramMap.entrySet();
Iterator<Map.Entry<String, String[]>> it = entries.iterator();
while (it.hasNext()) {
Map.Entry<String, String[]> entry = it.next();
String[] values = entry.getValue();
List<String> valList = new ArrayList<String>();
if (values != null) {
for (String value : values) {
valList.add(escapeHTML(value));
}
dO.removeParameter(entry.getKey());
//Please note that Parameter is a hashMap so , Is it required to remove the entry first before inserting or it will replace the new value associated with key . How it works in Java ?
dO.addParameter(entry.getKey(),valList.toArray(new String[valList.size()]));
}
}
}