я пишу следующий код, но при этом работать он генерирует ConcurrentModificationExceptionConcurrentModificationException HashMap в Java
if(attendancePolicy.getType().equals(AttendanceConstants.EMPLOYEE_ATTENDANCE_POLICY)) {
synchronized(attendancePolicy.getListEmployee()) {
for(EmployeeAttendancePolicy employeeAttendancePolicy : attendancePolicy.getListEmployee()) {
employeeInfo = employeeInfoSessionBeanLocal.findEmployeeInfoEntityByEmployeeInfoId(
employeeAttendancePolicy.getEmployeeId());
if(employeeInfo != null) {
employeeAttendancePolicy.setEmpName(
employeeInfo.getFirstName() + " "
+ employeeInfo.getMiddleName() + " "
+ employeeInfo.getLastName());
company = companySessionBeanLocal.findCompanyById(employeeInfo.getCompanyId());
employeeAttendancePolicy.setCompanyName(company.getName());
department = departmentSessionBeanLocal.findDepartmentEntityByDepartmentId(
employeeInfo.getDepartmentId());
employeeAttendancePolicy.setDepartmentName(department.getName());
}
else {
attendancePolicy.getListEmployee().remove(employeeAttendancePolicy);
}
}
}
}
Возможный дубликат [Итерирование в коллекции, исключая ConcurrentModificationException при удалении в цикле] (http://stackoverflow.com/questions/223918/iterating-through-a-collection-avoiding-concurrentmodificationexception-when-re) – Raedwald