From a047c3682a5dab463c02acf7fe6d13659befb9f7 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Wed, 5 Apr 2017 22:40:22 +0300 Subject: [PATCH] Invalidate cache version if corresponding file is empty Sometimes an expression `versionFile.readText()` returns an empty string, so that `toInt()` fails with `NumberFormatException`. It can happen in with both JPS and Gradle. I could not reproduce the problem, and it seems to be impossible (under normal circumstances), because we always write a non-empty string, and the file is checked to exist before reading. Maybe it could be caused by an FS error. The only "solution" to the problem I could think is to swallow the exception, and assume that cache version is not valid (so it would cause a rebuild of a module). #KT-17125 fixed --- .../jetbrains/kotlin/incremental/CacheVersion.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build-common/src/org/jetbrains/kotlin/incremental/CacheVersion.kt b/build-common/src/org/jetbrains/kotlin/incremental/CacheVersion.kt index 481672b8c97..7a6d9b4c64d 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/CacheVersion.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/CacheVersion.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.config.IncrementalCompilation import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion import java.io.File +import java.io.IOException private val NORMAL_VERSION = 8 private val EXPERIMENTAL_VERSION = 4 @@ -40,8 +41,16 @@ class CacheVersion( ) { private val isEnabled by lazy(isEnabled) - private val actualVersion: Int - get() = versionFile.readText().toInt() + private val actualVersion: Int? + get() = try { + versionFile.readText().toInt() + } + catch (e: NumberFormatException) { + null + } + catch (e: IOException) { + null + } private val expectedVersion: Int get() {