Do not swallow any exceptions apart FNFE
Relates to #KT-39776
This commit is contained in:
committed by
Space
parent
cf830887ec
commit
81efdab4e4
+3
-4
@@ -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)
|
||||
})
|
||||
|
||||
|
||||
+10
-10
@@ -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}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user