Skip to content

Commit

Permalink
Merge pull request #831 from scireum/feature/aha/j16-fix
Browse files Browse the repository at this point in the history
Avoids a ConcurrentModificationException in Java9+.
  • Loading branch information
sabieber authored Apr 16, 2021
2 parents 7778da3 + 1cd9fdc commit 97c2a92
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/sirius/pasta/tagliatelle/Tagliatelle.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -93,7 +94,20 @@ public MultiMap<String, String> getTagLibTags() {
*/
public List<TemplateExtension> getExtensions(String target) {
synchronized (extensions) {
return Collections.unmodifiableList(extensions.computeIfAbsent(target, this::loadExtensions));
List<TemplateExtension> result = extensions.get(target);
if (result == null) {
// As we might re-enter this method while compiling templates in "loadExtensions" we provide a
// placeholder value here to avoid infinite recursions. (Under normal circumstances, this shouldn't
// happen anyway, as cyclic extensions make no sense at all).
extensions.put(target, new ArrayList<>());

// Load and fill the result list. Note that we cannot use HashMap.computeIfAbsent here, as
// loadExtensions itself compiles templates which might end up calling this method leading
// to a ConcurrentModificationException...
result = loadExtensions(target);
extensions.put(target, result);
}
return Collections.unmodifiableList(result);
}
}

Expand Down

0 comments on commit 97c2a92

Please sign in to comment.