From c2db059b34a60cfb9d66d5c186841749a177e117 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 2 Dec 2015 11:29:00 +0100 Subject: [PATCH] assert file & document validity on getText (EA-75987 - assert: ShredImpl.) --- .../src/com/intellij/psi/impl/PsiDocumentManagerBase.java | 4 ++++ .../src/com/intellij/psi/impl/source/PsiFileImpl.java | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java index a1ae0dd3bdce..4c69ae4c8022 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java +++ b/platform/core-impl/src/com/intellij/psi/impl/PsiDocumentManagerBase.java @@ -613,6 +613,10 @@ public abstract class PsiDocumentManagerBase extends PsiDocumentManager implemen Document delegate = window.getDelegate(); if (delegate instanceof FrozenDocument) return (DocumentEx)window; + if (!window.isValid()) { + throw new AssertionError("host committed: " + isCommitted(delegate) + ", window=" + window); + } + UncommittedInfo info = myUncommittedInfos.get(delegate); DocumentWindow answer = info == null ? null : info.myFrozenWindows.get(document); if (answer == null) answer = freezeWindow(window); diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java index ce23f3a24192..5dc36b5c6b43 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/PsiFileImpl.java @@ -47,6 +47,7 @@ import com.intellij.psi.search.PsiElementProcessor; import com.intellij.psi.search.SearchScope; import com.intellij.psi.stubs.*; import com.intellij.psi.tree.*; +import com.intellij.psi.util.PsiUtilCore; import com.intellij.reference.SoftReference; import com.intellij.util.FileContentUtilCore; import com.intellij.util.IncorrectOperationException; @@ -385,6 +386,10 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF @Override public String getText() { + final ASTNode tree = derefTreeElement(); + if (tree != null) return tree.getText(); + + PsiUtilCore.ensureValid(this); return getViewProvider().getContents().toString(); } @@ -393,6 +398,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF final ASTNode tree = derefTreeElement(); if (tree != null) return tree.getTextLength(); + PsiUtilCore.ensureValid(this); return getViewProvider().getContents().length(); }