From 81efdab4e484891d5370e05ffe338eae509744b1 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Wed, 24 Feb 2021 11:06:49 +0000 Subject: [PATCH] Do not swallow any exceptions apart FNFE Relates to #KT-39776 --- .../load/kotlin/KotlinBinaryClassCache.kt | 7 +++---- .../load/kotlin/VirtualFileKotlinClass.kt | 20 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinBinaryClassCache.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinBinaryClassCache.kt index 1ec5289d942..49ff93c8e88 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinBinaryClassCache.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinBinaryClassCache.kt @@ -27,9 +27,9 @@ import java.util.concurrent.CopyOnWriteArrayList class KotlinBinaryClassCache : Disposable { private class RequestCache { - internal var virtualFile: VirtualFile? = null - internal var modificationStamp: Long = 0 - internal var result: KotlinClassFinder.Result? = null + var virtualFile: VirtualFile? = null + var modificationStamp: Long = 0 + var result: KotlinClassFinder.Result? = null fun cache( file: VirtualFile, @@ -82,7 +82,6 @@ class KotlinBinaryClassCache : Disposable { } val aClass = ApplicationManager.getApplication().runReadAction(Computable { - @Suppress("DEPRECATION") VirtualFileKotlinClass.create(file, fileContent) }) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/VirtualFileKotlinClass.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/VirtualFileKotlinClass.kt index 0e5b950f0de..c6d6680d7a7 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/VirtualFileKotlinClass.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/VirtualFileKotlinClass.kt @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.load.kotlin.KotlinClassFinder.Result.KotlinClass import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.util.PerformanceCounter -import org.jetbrains.kotlin.utils.rethrow import java.io.FileNotFoundException import java.io.IOException @@ -43,8 +42,7 @@ class VirtualFileKotlinClass private constructor( try { return file.contentsToByteArray() } catch (e: IOException) { - LOG.error(renderFileReadingErrorMessage(file), e) - throw rethrow(e) + throw logFileReadingErrorMessage(e, file) } } @@ -56,14 +54,13 @@ class VirtualFileKotlinClass private constructor( private val LOG = Logger.getInstance(VirtualFileKotlinClass::class.java) private val perfCounter = PerformanceCounter.create("Binary class from Kotlin file") - @Deprecated("Use KotlinBinaryClassCache") - fun create(file: VirtualFile, fileContent: ByteArray?): KotlinClassFinder.Result? { + internal fun create(file: VirtualFile, fileContent: ByteArray?): KotlinClassFinder.Result? { return perfCounter.time { assert(file.fileType == JavaClassFileType.INSTANCE) { "Trying to read binary data from a non-class file $file" } try { val byteContent = fileContent ?: file.contentsToByteArray(false) - if (!byteContent.isEmpty()) { + if (byteContent.isNotEmpty()) { val kotlinJvmBinaryClass = FileBasedKotlinClass.create(byteContent) { name, classVersion, header, innerClasses -> VirtualFileKotlinClass(file, name, classVersion, header, innerClasses) } @@ -74,15 +71,18 @@ class VirtualFileKotlinClass private constructor( } catch (e: FileNotFoundException) { // Valid situation. User can delete jar file. } catch (e: Throwable) { - if (e is ControlFlowException) { - throw e - } - LOG.warn(renderFileReadingErrorMessage(file), e) + if (e is ControlFlowException) throw e + throw logFileReadingErrorMessage(e, file) } null } } + private fun logFileReadingErrorMessage(e: Throwable, file: VirtualFile): Throwable { + LOG.warn(renderFileReadingErrorMessage(file), e) + return e + } + private fun renderFileReadingErrorMessage(file: VirtualFile): String = "Could not read file: ${file.path}; size in bytes: ${file.length}; file type: ${file.fileType.name}" }