Skip to content

Bug Report: IllegalStateException in EasyCode Plugin During Quick Fix Invocation #325

@NickDev70

Description

@NickDev70

Dear EasyCode Plugin Development Team,

I am writing to report a bug in the EasyCode plugin for IntelliJ IDEA, which causes an IllegalStateException when invoking the "Quick fix with EasyCode" intention. Below are the details of the issue, including the error description, stack trace, and suggested steps for resolution.

Issue Description

When attempting to use the "Quick fix with EasyCode" intention, an exception occurs, preventing the action from completing. The error is related to an improper call to invokeAndWait from a read-action context, which leads to a potential deadlock. This issue appears to be triggered during the generation of the intention preview (IntentionAction.generatePreview).

Error Details

The following exception is logged in the IntelliJ IDEA log file (idea.log):

java.lang.IllegalStateException: Calling invokeAndWait from read-action leads to possible deadlock.
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:480)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:526)
    at a.a.k.a.invoke(a.java:76)
    at com.intellij.codeInsight.intention.IntentionAction.generatePreview(IntentionAction.java:116)
    ...
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:750)

Context

  • Plugin: EasyCode (exact version unknown, please advise how to confirm).
  • IDE: IntelliJ IDEA (exact version: 21.0.6+9-b895.109 amd64 (JCEF 122.1.9) VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.).
  • Action: Invoking the "Quick fix with EasyCode" intention, likely during code generation or modification.
  • Impact: The quick fix fails, and the IDE logs the error, disrupting the workflow.

Root Cause

The exception indicates that the plugin's code (specifically in the obfuscated class a.a.k.a at line 76) calls ApplicationImpl.invokeAndWait from a read-action context. According to the IntelliJ Platform documentation, this is not allowed as it can cause deadlocks. The issue arises during the intention preview generation (IntentionPreviewComputable), which is part of the IntelliJ IDEA intention framework.

Suggested Fix

To resolve this issue, the plugin's code should be updated to avoid calling invokeAndWait from a read-action. Possible approaches include:

  1. Replace invokeAndWait with invokeLater:
    • Use ApplicationManager.getApplication().invokeLater to schedule the operation asynchronously, ensuring it runs outside the read-action.
    • Example:
      ApplicationManager.getApplication().invokeLater(() -> {
          WriteCommandAction.runWriteCommandAction(project, () -> {
              // Perform file or model modifications here
          });
      });
  2. Restructure the logic:
    • Ensure that operations requiring write-access are executed within a proper write-action context using WriteCommandAction.
    • Avoid invoking blocking operations during intention preview generation.
  3. Disable preview if unsupported:
    • If the preview feature is not critical, consider disabling it for the affected intention to avoid triggering the problematic code path.

Steps to Reproduce

  1. Open a project in IntelliJ IDEA with the EasyCode plugin installed.
  2. Trigger the "Quick fix with EasyCode" intention (e.g., via Alt+Enter on a supported code element).
  3. Observe the error in the IDE's log file (idea.log) and the failure of the quick fix action.

Additional Information

  • The issue may be specific to certain file types (e.g., Java or Kotlin) or actions, but this needs confirmation.
  • Disabling the intention preview feature in IntelliJ IDEA (Settings > Editor > General > Quick Fixes) temporarily mitigates the issue but is not a long-term solution.
  • The problem may be related to compatibility between the plugin and the IntelliJ IDEA version, which requires further investigation.

Request

Please investigate this issue and provide a fix in a future release of the EasyCode plugin. If additional details are needed (e.g., specific versions, project setup, or full logs), let me know, and I can provide them. Additionally, please confirm whether this issue is already known or tracked in your issue tracker.

Thank you for your attention to this matter. I look forward to your response and a resolution to this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions