From 8a40015a76712ac25455b04837f429e200ea7dd8 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 18 Apr 2017 13:18:52 +0300 Subject: [PATCH] platform: always load functional interfaces from Kotlin stdlib by platform classloader This is needed to allow using methods with Kotlin functional parameters in API (IDEA-171552). --- .../intellij/ide/plugins/cl/PluginClassLoader.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java b/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java index 1810a37dd820..5aab969e8d8d 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java +++ b/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java @@ -71,7 +71,10 @@ public class PluginClassLoader extends UrlClassLoader { // a different version of which is used in IDEA. @Nullable private Class tryLoadingClass(@NotNull String name, final boolean resolve, @Nullable Set visited) { - Class c = loadClassInsideSelf(name); + Class c = null; + if (!mustBeLoadedByPlatform(name)) { + c = loadClassInsideSelf(name); + } if (c == null) { c = loadClassFromParents(name, visited); @@ -87,6 +90,13 @@ public class PluginClassLoader extends UrlClassLoader { return null; } + private static boolean mustBeLoadedByPlatform(String className) { + //FunctionX interfaces from kotlin-runtime must be loaded by the platform classloader. Otherwise if a plugin bundles its own version + // of kotlin-runtime.jar it won't be possible to call platform's methods with Kotlin functional types in signatures from such a plugin. + //We assume that FunctionX interfaces don't change between Kotlin versions so it's safe to always load them from platform's kotlin-runtime. + return className.startsWith("kotlin.jvm.functions."); + } + @Nullable private Class loadClassFromParents(final String name, Set visited) { for (ClassLoader parent : myParents) {