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 {
|
class KotlinBinaryClassCache : Disposable {
|
||||||
private class RequestCache {
|
private class RequestCache {
|
||||||
internal var virtualFile: VirtualFile? = null
|
var virtualFile: VirtualFile? = null
|
||||||
internal var modificationStamp: Long = 0
|
var modificationStamp: Long = 0
|
||||||
internal var result: KotlinClassFinder.Result? = null
|
var result: KotlinClassFinder.Result? = null
|
||||||
|
|
||||||
fun cache(
|
fun cache(
|
||||||
file: VirtualFile,
|
file: VirtualFile,
|
||||||
@@ -82,7 +82,6 @@ class KotlinBinaryClassCache : Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val aClass = ApplicationManager.getApplication().runReadAction(Computable {
|
val aClass = ApplicationManager.getApplication().runReadAction(Computable {
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
VirtualFileKotlinClass.create(file, fileContent)
|
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.load.kotlin.header.KotlinClassHeader
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.util.PerformanceCounter
|
import org.jetbrains.kotlin.util.PerformanceCounter
|
||||||
import org.jetbrains.kotlin.utils.rethrow
|
|
||||||
import java.io.FileNotFoundException
|
import java.io.FileNotFoundException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@@ -43,8 +42,7 @@ class VirtualFileKotlinClass private constructor(
|
|||||||
try {
|
try {
|
||||||
return file.contentsToByteArray()
|
return file.contentsToByteArray()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
LOG.error(renderFileReadingErrorMessage(file), e)
|
throw logFileReadingErrorMessage(e, file)
|
||||||
throw rethrow(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,14 +54,13 @@ class VirtualFileKotlinClass private constructor(
|
|||||||
private val LOG = Logger.getInstance(VirtualFileKotlinClass::class.java)
|
private val LOG = Logger.getInstance(VirtualFileKotlinClass::class.java)
|
||||||
private val perfCounter = PerformanceCounter.create("Binary class from Kotlin file")
|
private val perfCounter = PerformanceCounter.create("Binary class from Kotlin file")
|
||||||
|
|
||||||
@Deprecated("Use KotlinBinaryClassCache")
|
internal fun create(file: VirtualFile, fileContent: ByteArray?): KotlinClassFinder.Result? {
|
||||||
fun create(file: VirtualFile, fileContent: ByteArray?): KotlinClassFinder.Result? {
|
|
||||||
return perfCounter.time {
|
return perfCounter.time {
|
||||||
assert(file.fileType == JavaClassFileType.INSTANCE) { "Trying to read binary data from a non-class file $file" }
|
assert(file.fileType == JavaClassFileType.INSTANCE) { "Trying to read binary data from a non-class file $file" }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val byteContent = fileContent ?: file.contentsToByteArray(false)
|
val byteContent = fileContent ?: file.contentsToByteArray(false)
|
||||||
if (!byteContent.isEmpty()) {
|
if (byteContent.isNotEmpty()) {
|
||||||
val kotlinJvmBinaryClass = FileBasedKotlinClass.create(byteContent) { name, classVersion, header, innerClasses ->
|
val kotlinJvmBinaryClass = FileBasedKotlinClass.create(byteContent) { name, classVersion, header, innerClasses ->
|
||||||
VirtualFileKotlinClass(file, name, classVersion, header, innerClasses)
|
VirtualFileKotlinClass(file, name, classVersion, header, innerClasses)
|
||||||
}
|
}
|
||||||
@@ -74,15 +71,18 @@ class VirtualFileKotlinClass private constructor(
|
|||||||
} catch (e: FileNotFoundException) {
|
} catch (e: FileNotFoundException) {
|
||||||
// Valid situation. User can delete jar file.
|
// Valid situation. User can delete jar file.
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (e is ControlFlowException) {
|
if (e is ControlFlowException) throw e
|
||||||
throw e
|
throw logFileReadingErrorMessage(e, file)
|
||||||
}
|
|
||||||
LOG.warn(renderFileReadingErrorMessage(file), e)
|
|
||||||
}
|
}
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun logFileReadingErrorMessage(e: Throwable, file: VirtualFile): Throwable {
|
||||||
|
LOG.warn(renderFileReadingErrorMessage(file), e)
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
private fun renderFileReadingErrorMessage(file: VirtualFile): String =
|
private fun renderFileReadingErrorMessage(file: VirtualFile): String =
|
||||||
"Could not read file: ${file.path}; size in bytes: ${file.length}; file type: ${file.fileType.name}"
|
"Could not read file: ${file.path}; size in bytes: ${file.length}; file type: ${file.fileType.name}"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user