Fight with valid absent, corrupted and missing files in archives (EA-119686)

Inspired by ClassFileViewProvider.
This commit is contained in:
Nikolay Krasko
2018-05-11 13:05:59 +03:00
parent c35f8d621a
commit f2c642eefb
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.idea.decompiler.classFile
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.ClassFileViewProvider
@@ -51,7 +52,7 @@ fun isKotlinWithCompatibleAbiVersion(file: VirtualFile): Boolean {
*/
fun isKotlinInternalCompiledFile(file: VirtualFile, fileContent: ByteArray? = null): Boolean {
// Don't crash on invalid files (EA-97751)
if (!file.isValid || fileContent?.size == 0) {
if (!file.isValid || fileContent?.size == 0 || !file.exists()) {
return false
}
@@ -60,10 +61,19 @@ fun isKotlinInternalCompiledFile(file: VirtualFile, fileContent: ByteArray? = nu
}
val innerClass =
if (fileContent == null)
try {
if (fileContent == null) {
ClassFileViewProvider.isInnerClass(file)
else
} else {
ClassFileViewProvider.isInnerClass(file, fileContent)
}
} catch (exception: Exception) {
Logger
.getInstance("org.jetbrains.kotlin.idea.decompiler.classFile.isKotlinInternalCompiledFile")
.debug(file.path, exception)
return false
}
if (innerClass) {
return true
@@ -73,7 +83,7 @@ fun isKotlinInternalCompiledFile(file: VirtualFile, fileContent: ByteArray? = nu
if (header.classId.isLocal) return true
return header.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS ||
header.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART
header.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART
}
fun findMultifileClassParts(file: VirtualFile, classId: ClassId, partNames: List<String>): List<KotlinJvmBinaryClass> {