From a30d0d0f1ef501f29c5cf40c828c2bd85cff168c Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 17 Oct 2016 22:16:54 +0300 Subject: [PATCH] Commit all documents after J2K (KT-13584, EA-82451) New Kotlin file will be generated after converting, they are created for virtual files that were renamed from Java. The exception happens when Java file was previously opened in editor, in that case text is restored through getLastCommittedText(document) where document is resored for virtual file. See: SingleRootFileViewProvider.VirtualFileContent.getText() Exception descriptions also mention "Create Test" action as a problem source. The issue was reproduced when J2K convertion was performed on test creation. (cherry picked from commit e44260a) #KT-13584 Fixed --- .../org/jetbrains/kotlin/idea/actions/JavaToKotlinAction.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/JavaToKotlinAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/JavaToKotlinAction.kt index 238aa5cf1b9..a4dbd742ef7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/actions/JavaToKotlinAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/actions/JavaToKotlinAction.kt @@ -89,7 +89,7 @@ class JavaToKotlinAction : AnAction() { } } catch (e: IOException) { - MessagesEx.error(psiFile.project, e.message).showLater() + MessagesEx.error(psiFile.project, e.message ?: "").showLater() } } return result @@ -138,6 +138,8 @@ class JavaToKotlinAction : AnAction() { externalCodeUpdate?.invoke() + PsiDocumentManager.getInstance(project).commitAllDocuments() + newFiles.singleOrNull()?.let { FileEditorManager.getInstance(project).openFile(it, true) }