as the title suggests, I need to fix this exception: java.util.ConcurrentModificationException: null. Below the code that goes into error:
Map<String, List<Note>> noteByCod = notes.stream().collect(Collectors.groupingBy(Note::getCod));
noteByCod.forEach((k, v) -> v.forEach(note -> {
if (!note.getVer() || !StringUtils.isEmpty(note.getError())) {
noteByCod.remove(k);
}
}));
the problem is that it is not possible to modify the collection you are iterating on, in this case how would you solve?
noteByCod.values().removeIf(v -> v.stream().anyMatch(note -> !note.getVer() || !StringUtils.isEmpty(note.getError())));And when you clean up your API and make a definite decision whether an error free note should returnnullor an empty string fromgetError(), you can get rid ofStringUtils.isEmptyand use eithergetError() != nullor!getError().isEmpty().