I understand the concept behind it but thought using ConcurrentHashMap instead of HashMap will fix it. Because ConcurrentHashMap protects from concurrent reading and modification by different threads.
But I still see the exception.
Here's the code snippet-
SampleFile.java
prepareInfo(RequestHelper.getSender(request), someVar, concurrentMap);
....
...
private void prepareInfo(final Sender sender, final SomeVar someVar, final ConcurrentHashMap<String,
Object> concurrentMap){
final Info info = RequestHelper.getInfo(someVar);
someVar.setInfo(info);
if(sender != null){
prepareProfileInfo(sender.getUserDetails(), info, concurrentMap);
mapDetailsWithMap(sender.getDetails(), concurrentMap);
if(sender.getSenderId() != null){
concurrentMap.put("sender_id", sender.getSenderId());
}
concurrentMap.putAll(sender.getAdditionalProperties());
}
}
The error stacktrace is -
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1445)
at java.util.HashMap$EntryIterator.next(HashMap.java:1479)
at java.util.HashMap$EntryIterator.next(HashMap.java:1477)
at java.util.concurrent.ConcurrentHashMap.putAll(ConcurrentHashMap.java:1083)
at SampleFile.prepareAccountInfo(SampleFile.java:114)
Couple of questions I am not clear about -
- Why is the exception still happening?
- Is there a way we can test the fix via Unit Test?