From 3a609a94728a5118f2336470b1dc8e5a34f3f178 Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Thu, 22 Feb 2018 12:50:09 +0300 Subject: [PATCH] Assertions to catch EA-114080 --- .../src/org/jetbrains/kotlin/psi/KtElementImpl.java | 6 +++++- .../src/org/jetbrains/kotlin/psi/KtElementImplStub.java | 6 +++++- .../src/org/jetbrains/kotlin/psi/KtLambdaExpression.java | 6 +++++- .../psi/synthetics/SyntheticClassOrObjectDescriptor.kt | 6 +++++- .../kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt | 5 ++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtElementImpl.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtElementImpl.java index a88c3c8a0f3..b42a01928f5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtElementImpl.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtElementImpl.java @@ -56,7 +56,11 @@ public class KtElementImpl extends ASTWrapperPsiElement implements KtElement { @Override public KtFile getContainingKtFile() { PsiFile file = getContainingFile(); - assert file instanceof KtFile : "KtElement not inside KtFile: " + file + (file == null ? "" : " " + file.getText()); + if(!(file instanceof KtFile)) { + String fileString = (file != null && file.isValid()) ? file.getText() : ""; + throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString + + "for element " + this + " of type " + this.getClass() + " node = " + getNode()); + } return (KtFile) file; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtElementImplStub.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtElementImplStub.java index 96e897cdd13..5d239beb837 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtElementImplStub.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtElementImplStub.java @@ -67,7 +67,11 @@ public class KtElementImplStub> extends StubBasedPsiEle @Override public KtFile getContainingKtFile() { PsiFile file = getContainingFile(); - assert file instanceof KtFile : "KtElement not inside KtFile: " + file + " " + (file.isValid() ? file.getText() : ""); + if(!(file instanceof KtFile)) { + String fileString = file.isValid() ? file.getText() : ""; + throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString + + "for element " + this + " of type " + this.getClass() + " node = " + getNode()); + } return (KtFile) file; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtLambdaExpression.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtLambdaExpression.java index ef0cd19da02..a3434080e0d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtLambdaExpression.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtLambdaExpression.java @@ -77,7 +77,11 @@ public class KtLambdaExpression extends LazyParseablePsiElement implements KtExp @Override public KtFile getContainingKtFile() { PsiFile file = getContainingFile(); - assert file instanceof KtFile : "KtElement not inside KtFile: " + file + " " + file.getText(); + if(!(file instanceof KtFile)) { + String fileString = (file != null && file.isValid()) ? file.getText() : ""; + throw new IllegalStateException("KtElement not inside KtFile: " + file + fileString + + "for element " + this + " of type " + this.getClass() + " node = " + getNode()); + } return (KtFile) file; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/synthetics/SyntheticClassOrObjectDescriptor.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/synthetics/SyntheticClassOrObjectDescriptor.kt index 2abbd279b19..00339d43728 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/synthetics/SyntheticClassOrObjectDescriptor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/synthetics/SyntheticClassOrObjectDescriptor.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.AbstractClassTypeConstructor import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeConstructor +import java.lang.IllegalStateException /* * This class introduces all attributes that are needed for synthetic classes/object so far. @@ -151,7 +152,10 @@ class SyntheticClassOrObjectDescriptor( override fun getPsiOrParent() = _parent.psiOrParent override fun getParent() = _parent.psiOrParent - override fun getContainingKtFile() = _parent.containingKtFile + override fun getContainingKtFile() = + // in theory `containingKtFile` is `@NotNull` but in practice EA-114080 + _parent.containingKtFile ?: throw IllegalStateException("containingKtFile was null for $_parent of ${_parent.javaClass}") + } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt index f1d39be0e33..76d9e78c756 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt @@ -62,7 +62,10 @@ data class PlatformAnalysisSettings(val platform: TargetPlatform, val sdk: Sdk?, class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService { override fun getResolutionFacade(elements: List): ResolutionFacade { - return getFacadeToAnalyzeFiles(elements.map { it.containingKtFile }) + return getFacadeToAnalyzeFiles(elements.map { + // in theory `containingKtFile` is `@NotNull` but in practice EA-114080 + it.containingKtFile ?: throw IllegalStateException("containingKtFile was null for $it of ${it.javaClass}") + }) } override fun getSuppressionCache(): KotlinSuppressCache = kotlinSuppressCache.value