Skip to content

Commit ee7a79c

Browse files
committed
fix(java-auto-test): ensure thread safety when finding and parsing PsiJavaFile
Previously, the `PsiJavaFile` was loaded without ensuring thread safety, which could lead to race conditions and inconsistent results. This commit introduces a `runReadAction` block to guarantee that the file is loaded and parsed in a thread-safe manner, preventing potential issues with concurrent access.
1 parent fc47e49 commit ee7a79c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

java/src/main/kotlin/cc/unitmesh/idea/service/JavaAutoTestService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ class JavaAutoTestService : AutoTestService() {
161161
): GradleRunConfiguration? {
162162
val name = virtualFile.name
163163

164-
val psiFile: PsiJavaFile = PsiManager.getInstance(project).findFile(virtualFile) as? PsiJavaFile ?: return null
165-
val canonicalName = runReadAction { psiFile.packageName + "." + virtualFile.nameWithoutExtension }
164+
val canonicalName = runReadAction {
165+
val psiFile: PsiJavaFile = PsiManager.getInstance(project).findFile(virtualFile) as? PsiJavaFile ?: return@runReadAction null
166+
psiFile.packageName + "." + virtualFile.nameWithoutExtension
167+
} ?: return null
166168

167169
val runManager = RunManager.getInstance(project)
168170

0 commit comments

Comments
 (0)