From 9807643b0e3b37447f3ac259c43faea24e2fc624 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 24 Dec 2014 18:02:19 +0300 Subject: [PATCH] Synchronize access to mutable class loader reference in CompilerRunnerUtil --- .../compiler/runner/CompilerRunnerUtil.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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(