package org.jetbrains.plugins.groovy.util;

import com.intellij.util.containers.ConcurrentHashMap;
import org.jetbrains.annotations.NotNull;

/**
 * @author Sergey Evdokimov
 */
public class ClassInstanceCache {

  private static final ConcurrentHashMap<String, Object> CACHE = new ConcurrentHashMap<String, Object>();

  private ClassInstanceCache() {
  }

  @SuppressWarnings("unchecked")
  public static <T> T getInstance(@NotNull String className) {
    Object res = CACHE.get(className);
    if (res != null) return (T)res;

    try {
      Object instance = Class.forName(className).newInstance();

      Object oldValue = CACHE.putIfAbsent(className, instance);
      if (oldValue != null) {
        instance = oldValue;
      }

      return (T)instance;
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  
}

@@ -37,16 +37,117 @@
 .util;%0A%0A
+import com.intellij.ide.plugins.IdeaPluginDescriptor;%0Aimport com.intellij.ide.plugins.PluginManager;%0A
 import c
@@ -452,16 +452,636 @@
  %7B%0A  %7D%0A%0A
+  private static Object createInstance(@NotNull String className) %7B%0A    try %7B%0A      try %7B%0A        return Class.forName(className).newInstance();%0A      %7D%0A      catch (ClassNotFoundException e) %7B%0A        for (IdeaPluginDescriptor descriptor : PluginManager.getPlugins()) %7B%0A          try %7B%0A            return descriptor.getPluginClassLoader().loadClass(className).newInstance();%0A          %7D%0A          catch (ClassNotFoundException ignored) %7B%0A%0A          %7D%0A        %7D%0A%0A        throw new RuntimeException(%22Class not found: %22 + className);%0A      %7D%0A    %7D%0A    catch (Exception e) %7B%0A      throw new RuntimeException(e);%0A    %7D%0A  %7D%0A%0A
   @Suppr
@@ -1219,25 +1219,25 @@
 if (res 
-!
+=
 = null) 
 return (
@@ -1232,95 +1232,46 @@
 ll) 
-return (T)res;%0A%0A    try %7B%0A      Object instance = Class.forName(className).newInstance(
+%7B%0A      res = createInstance(className
 );%0A%0A
@@ -1323,24 +1323,19 @@
 ssName, 
-instance
+res
 );%0A     
@@ -1367,24 +1367,19 @@
         
-instance
+res
  = oldVa
@@ -1387,27 +1387,31 @@
 ue;%0A      %7D%0A
-%0A
   
+  %7D%0A%0A
     return (
@@ -1416,92 +1416,12 @@
  (T)
-instance;%0A    %7D%0A    catch (Exception e) %7B%0A      throw new RuntimeException(e);%0A    %7D
+res;
 %0A  %7D

Fix EA-30104: ClassNotFound exception: Don't forget that plugins loaded by different class loader.