diff --git a/python/src/com/jetbrains/python/psi/resolve/PythonPathCache.java b/python/src/com/jetbrains/python/psi/resolve/PythonPathCache.java index 695471955132..918973790175 100644 --- a/python/src/com/jetbrains/python/psi/resolve/PythonPathCache.java +++ b/python/src/com/jetbrains/python/psi/resolve/PythonPathCache.java @@ -33,7 +33,7 @@ import java.util.stream.Collectors; * @author yole */ public abstract class PythonPathCache { - private final Map>> myCache = ContainerUtil.newConcurrentMap(); + private final Map>> myCache = ContainerUtil.newConcurrentMap(); private final Map> myQNameCache = ContainerUtil.newConcurrentMap(); public void clearCache() { @@ -46,21 +46,21 @@ public abstract class PythonPathCache { */ @Nullable public List get(@NotNull final QualifiedName qualifiedName) { - final List> references = myCache.get(qualifiedName); + final SoftReference> references = myCache.get(qualifiedName); if (references == null) { return null; } - final List result = references.stream().map(r -> r.get()).collect(Collectors.toList()); - if (result.stream().anyMatch(o -> o == null || ! o.isValid())) { - // Null in list means SoftReference has been collected meaning cache is not valid + final List elements = references.get(); + if(elements != null && ! elements.stream().allMatch(PsiElement::isValid)) { + // At least one element is invalid return null; } - return result; + return elements; } public void put(QualifiedName qualifiedName, List results) { if (results != null) { - myCache.put(qualifiedName, new ArrayList<>(results.stream().map(e -> new SoftReference<>(e)).collect(Collectors.toList()))); + myCache.put(qualifiedName, new SoftReference<>(results)); } }