Skip to content

Commit

Permalink
potential deadlock with computeIfAbsent #1397
Browse files Browse the repository at this point in the history
  • Loading branch information
elucash committed Aug 25, 2022
1 parent e2dfb55 commit abed126
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions value-processor/src/org/immutables/value/processor/meta/Proto.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,18 @@ public ImmutableList<InjectionInfo> injectAnnotation() {
public static MetaAnnotated from(AnnotationMirror mirror, Environment environment) {
TypeElement element = (TypeElement) mirror.getAnnotationType().asElement();
String name = element.getQualifiedName().toString();
return metaAnnotatedCache()
.computeIfAbsent(name, n -> ImmutableProto.MetaAnnotated.of(element, name, environment));

ConcurrentMap<String, MetaAnnotated> cache = metaAnnotatedCache();
@Nullable MetaAnnotated metaAnnotated = cache.get(name);
if (metaAnnotated == null) {
metaAnnotated = ImmutableProto.MetaAnnotated.of(element, name, environment);
@Nullable MetaAnnotated existing = cache.putIfAbsent(name, metaAnnotated);
if (existing != null) {
metaAnnotated = existing;
}
}

return metaAnnotated;
}

private static ConcurrentMap<String, MetaAnnotated> metaAnnotatedCache() {
Expand Down

0 comments on commit abed126

Please sign in to comment.