diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java index ef74f50ee58..faac526d8c9 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java @@ -45,6 +45,19 @@ public class CompilerRunnerUtil { private static SoftReference ourClassLoaderRef = new SoftReference(null); + @NotNull + private static synchronized ClassLoader getOrCreateClassLoader( + @NotNull CompilerEnvironment environment, + @NotNull File libPath + ) throws IOException { + ClassLoader classLoader = ourClassLoaderRef.get(); + if (classLoader == null) { + classLoader = createClassLoader(libPath, environment.getParentClassLoader(), environment.getClassesToLoadByParent()); + ourClassLoaderRef = new SoftReference(classLoader); + } + return classLoader; + } + @Nullable private static File getLibPath(@NotNull KotlinPaths paths, @NotNull MessageCollector messageCollector) { File libs = paths.getLibPath(); @@ -130,11 +143,7 @@ public class CompilerRunnerUtil { File libPath = getLibPath(environment.getKotlinPaths(), messageCollector); if (libPath == null) return null; - ClassLoader classLoader = ourClassLoaderRef.get(); - if (classLoader == null) { - classLoader = createClassLoader(libPath, environment.getParentClassLoader(), environment.getClassesToLoadByParent()); - ourClassLoaderRef = new SoftReference(classLoader); - } + ClassLoader classLoader = getOrCreateClassLoader(environment, libPath); Class kompiler = Class.forName(compilerClassName, true, classLoader); Method exec = kompiler.getMethod(