From c175718dbf12b289da65260310697effa8ec45a2 Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 11 Feb 2017 14:25:50 +0100 Subject: [PATCH] during stub-ast switch, expose PSI to other threads only after it points to AST (could explain some of EA-96572 - failedToBindStubToAst) --- .../src/com/intellij/psi/impl/source/AstPathPsiMap.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/AstPathPsiMap.java b/platform/core-impl/src/com/intellij/psi/impl/source/AstPathPsiMap.java index 48d822bc4b7f..9b932d67e4c1 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/AstPathPsiMap.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/AstPathPsiMap.java @@ -87,8 +87,10 @@ class AstPathPsiMap { @NotNull StubBasedPsiElementBase cachePsi(@NotNull AstPath key, @NotNull StubBasedPsiElementBase psi) { myQueue.cleanupStaleReferences(); - myMap.put(key, new MyReference(psi, key, myQueue)); + // ensure PSI will use AST path before making it available to other threads + // otherwise another thread could invoke StubRef.getNode and fail since file's AST isn't set yet psi.setSubstrateRef(key); + myMap.put(key, new MyReference(psi, key, myQueue)); return psi; }