From 844a9d6975af1812b7791a115ec2a6224b817208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Nar=C4=99bski?= Date: Tue, 16 Sep 2025 17:17:20 +0200 Subject: [PATCH] EyeTracker: wrap call to getASTStructureElement() in runReadAction() This should fix the sporadic RuntimeExceptionWithAttachments exception in CodeGRITS plugin that happens on some projects when running eye tracker. com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: Read access is allowed from inside read-action only (see Application.runReadAction()); If you access or modify model on EDT consider wrapping your code in WriteIntentReadAction ; see https://jb.gg/ij-platform-threading for details [...] at trackers.EyeTracker.getASTStructureElement(EyeTracker.java:450) at trackers.EyeTracker.lambda$processRawData$1(EyeTracker.java:306) This fix is based on the https://stackoverflow.com/q/76809649 and the discussion in issue codegrits/CodeGRITS#17 . --- src/main/java/trackers/EyeTracker.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/trackers/EyeTracker.java b/src/main/java/trackers/EyeTracker.java index 207026e..51fe934 100644 --- a/src/main/java/trackers/EyeTracker.java +++ b/src/main/java/trackers/EyeTracker.java @@ -9,6 +9,7 @@ import com.intellij.openapi.fileEditor.FileEditorManagerEvent; import com.intellij.openapi.fileEditor.FileEditorManagerListener; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; @@ -250,7 +251,9 @@ public void processRawData(String message) { location.setAttribute("column", String.valueOf(logicalPosition.column)); location.setAttribute("path", RelativePathGetter.getRelativePath(filePath, projectPath)); gaze.appendChild(location); - Element aSTStructure = getASTStructureElement(psiElement); + Element aSTStructure = ApplicationManager.getApplication().runReadAction( + (Computable) () -> getASTStructureElement(psiElement) + ); gaze.appendChild(aSTStructure); lastElement = psiElement; // System.out.println(gaze.getAttribute("timestamp") + " " + System.currentTimeMillis());