"java.lang.IllegalStateException: read job must've been cancelled" when using KotlinAwareMoveFilesOrDirectoriesProcessor
Answered
Hi
I am writing a plugin that refactors directories for project with Java and Kotlin files.
I have code that repeatedly runs this in EDT CoroutineContext
val processor = KotlinAwareMoveFilesOrDirectoriesProcessor(
project = project,
elementsToMove = elementsToMove,
targetDirectory = destDirectory,
searchReferences = searchInComment,
searchInComments = true,
searchInNonJavaFiles = true,
moveCallback = null
)
processor.setPreviewUsages(false)
processor.setPrepareSuccessfulSwingThreadCallback(null)
CommandProcessor.getInstance().executeCommand(project, {
processor.run()
}, "Rename Package", null)
But sometimes (unpredictably, after about a minute of work) during the call to processor#run a multiple error occurs: java.lang.IllegalStateException: read job must've been cancelled.
java.lang.IllegalStateException: read job must've been cancelled
at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal(cancellableReadAction.kt:37)
at com.intellij.openapi.application.rw.InternalReadAction.tryReadCancellable(InternalReadAction.kt:93)
at com.intellij.openapi.application.rw.InternalReadAction.tryReadAction(InternalReadAction.kt:77)
at com.intellij.openapi.application.rw.InternalReadAction.readLoop(InternalReadAction.kt:64)
at com.intellij.openapi.application.rw.InternalReadAction.access$readLoop(InternalReadAction.kt:15)
at com.intellij.openapi.application.rw.InternalReadAction$readLoop$1.invokeSuspend(InternalReadAction.kt)
at _COROUTINE._BOUNDARY._(CoroutineDebugging.kt:42)
at com.intellij.application.options.codeStyle.cache.CodeStyleCachedValueProvider$AsyncComputation$start$2.invokeSuspend(CodeStyleCachedValueProvider.kt:135)
Caused by: java.lang.IllegalStateException: read job must've been cancelled
at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal(cancellableReadAction.kt:37)
at com.intellij.openapi.application.rw.InternalReadAction.tryReadCancellable(InternalReadAction.kt:93)
at com.intellij.openapi.application.rw.InternalReadAction.tryReadAction(InternalReadAction.kt:77)
(I realized that the error was in the call to processing#run via the async stack trace)
As a result, the work that the processor was supposed to do is not being done
Please sign in to leave a comment.
Why do you invoke
KotlinAwareMoveFilesOrDirectoriesProcessor
explicitly? Please explain the context/surrounding code.I need to move a large number of java/kotlin classes autonomously without user confirmation. Something like automatic project refactoring. As for
KotlinAwareMoveFilesOrDirectoriesProcessor
, it is the only one (as far as I understand) that can move packages with classes in both languages and correctly refactor the uses.Could you please verify this error still occurs with latest 2024.3 EAP release? https://www.jetbrains.com/idea/nextversion/