Dispose range markers in UI thread to prevent race condition at getting range (KT-28870)

#KT-28870 Fixed
This commit is contained in:
Nikolay Krasko
2019-01-18 17:03:47 +03:00
parent f19f38a4db
commit 80f1efaddc
2 changed files with 20 additions and 3 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.idea.conversion.copy
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.RangeMarker
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
@@ -32,4 +33,16 @@ val PsiElement.range: TextRange
get() = textRange!!
val RangeMarker.range: TextRange?
get() = if (isValid) TextRange(startOffset, endOffset) else null
get() = if (isValid) {
val start = startOffset
val end = endOffset
if (start in 0..end) {
TextRange(start, end)
} else {
// Probably a race condition had happened
LOG.error("Invalid range [$start, $end] for range marker (valid = $isValid)")
null
}
} else null
private val LOG = Logger.getInstance("RangeUtils")
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.idea.parameterInfo.custom
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorFactory
@@ -66,8 +67,11 @@ class KotlinCodeHintsModel(val project: Project) : EditorFactoryListenerWrapper
}
fun dispose() {
for (marker in lineEndMarkers.keys()) {
marker.dispose()
val keys = lineEndMarkers.keys()
ApplicationManager.getApplication().invokeLater {
for (marker in keys) {
marker.dispose()
}
}
}
}