package org.jetbrains.plugins.groovy.springloaded;

import com.intellij.debugger.PositionManager;
import com.intellij.debugger.PositionManagerFactory;
import com.intellij.debugger.engine.DebugProcess;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.NullableComputable;
import com.intellij.psi.JavaPsiFacade;

/**
 * Factory for position manager to debug classes reloaded by com.springsource.springloaded
 * @author Sergey Evdokimov
 */
public class SpringLoadedPositionManagerFactory extends PositionManagerFactory {

  @Override
  public PositionManager createPositionManager(final DebugProcess process) {
    return ApplicationManager.getApplication().runReadAction(new NullableComputable<PositionManager>() {
      @Override
      public PositionManager compute() {
        if (JavaPsiFacade.getInstance(process.getProject()).findPackage("com.springsource.loaded") != null) {
          return new SpringLoadedPositionManager(process);
        }
        return null;
      }
    });
  }
}

@@ -235,33 +235,26 @@
 cation.A
-pplicationManager
+ccessToken
 ;%0Aimport
@@ -279,31 +279,38 @@
 api.
-util.NullableComputable
+application.ApplicationManager
 ;%0Aim
@@ -649,22 +649,41 @@
 ) %7B%0A    
-return
+AccessToken accessToken =
  Applica
@@ -715,11 +715,15 @@
 n().
-run
+acquire
 Read
@@ -732,112 +732,26 @@
 tion
-(new NullableComputable%3CPositionManager%3E() %7B%0A      @Override%0A      public PositionManager compute()
+Lock();%0A    try
  %7B%0A
-  
     
@@ -858,26 +858,24 @@
 ) %7B%0A        
-  
 return new S
@@ -911,18 +911,16 @@
 ocess);%0A
-  
       %7D%0A
@@ -921,26 +921,24 @@
     %7D%0A      
-  
 return null;
@@ -946,19 +946,57 @@
     
-  %7D%0A    %7D);
+%7D%0A    finally %7B%0A      accessToken.finish();%0A    %7D
 %0A  %7D

Use ApplicationManager.getApplication().acquireReadActionLock() instead of ApplicationManager.getApplication().runReadAction()