【发布时间】:2019-07-05 13:12:49
【问题描述】:
我来了
ConcurrentModificationException(java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1558))
我怀疑我需要等到HashSet(nodeRefsWithTags) 完全填充后再处理它。或者有没有人有其他建议?
函数getTagRefs(sagerRef)被递归调用并填充nodeRefsWithTags。
nodeRefsWithTags = new HashSet<>();
getTagRefs(sagerRef);
List<Tag> tags = nodeRefsWithTags.stream()
.map(nodeRef -> ((List<NodeRef>)nodeService.getProperty(nodeRef, ContentModel.PROP_TAGS)))
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(taggingService::getTagName)
.collect(Collectors.groupingBy(tagName -> tagName, Collectors.counting()))
.entrySet().stream()
.map(map -> new Tag(map.getKey(), map.getValue()))
.collect(Collectors.toList());
【问题讨论】:
-
您能否分享Minimal, Complete, and Verifiable example,以便我们重现您的问题?使用您共享的代码,无法判断错误可能出在哪里。
-
引用的 Lambda 表达式似乎没问题。我想您省略的 stracktrace 指出了真正的问题......此外,调试代码将是您找出问题所在的最佳机会。
标签: java hashmap java-stream concurrentmodification