From cef7205f14b27efacb15216b84a315bef843ff6e Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 19 Feb 2018 10:31:33 +0300 Subject: [PATCH] Fix CCE caused by KotlinPackageSourcesMemberNamesIndex FileContentImpl::getPsiFile is not-nullable and at the same time it contains an explicit case of its fileType to LanguageFileType that leads to the following exception in case when kt-file is marked as plain text: java.lang.ClassCastException: com.intellij.openapi.file.exclude.EnforcedPlainTextFileTypeFactory$1 cannot be cast to com.intellij.openapi.fileTypes.LanguageFileType at com.intellij.util.indexing.FileContentImpl.createFileFromText(FileContentImpl.java:135) at com.intellij.util.indexing.FileContentImpl.getPsiFile(FileContentImpl.java:104) #EA-114338 Fixed --- .../idea/vfilefinder/KotlinPackageSourcesMemberNamesIndex.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinPackageSourcesMemberNamesIndex.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinPackageSourcesMemberNamesIndex.kt index 33cfcf972bc..30ae31432df 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinPackageSourcesMemberNamesIndex.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/vfilefinder/KotlinPackageSourcesMemberNamesIndex.kt @@ -30,10 +30,13 @@ object KotlinPackageSourcesMemberNamesIndex : FileBasedIndexExtension file.extension == KotlinFileType.EXTENSION } - override fun getVersion(): Int = 1 + override fun getVersion(): Int = 2 override fun getIndexer(): DataIndexer, FileContent> = DataIndexer { inputData -> + // Check if ".kt" file is marked as plain text + if (inputData.fileType !is KotlinFileType) return@DataIndexer emptyMap() + val ktFile = inputData.psiFile as? KtFile ?: return@DataIndexer emptyMap() val packageName = ktFile.packageDirective?.fqName?.asString() ?: ""