ClassLoader () { PluginClassLoader bestLoader = null; ClassLoader nonPluginLoader = null; Predicate<PluginClassLoader> isBetter = new java.util.function.Predicate<>() { private int myMaxIndex = -1; private Object2IntMap<ClassLoader> myMap = null; @Override public boolean test(@NotNull PluginClassLoader loader) { if (myMap == null) { List<IdeaPluginDescriptorImpl> plugins = PluginManagerCore.INSTANCE.getPluginSet().getEnabledModules(); int count = 0; myMap = new Object2IntOpenHashMap<>(plugins.size()); for (IdeaPluginDescriptor descriptor : plugins) { myMap.put(descriptor.getClassLoader(), count++); } } int index = myMap.applyAsInt(loader); boolean result = myMaxIndex < index; if (result) { myMaxIndex = index; } return result; } }; if (interfaces != null) { for (Class<?> anInterface : interfaces) { ClassLoader loader = anInterface.getClassLoader(); if (loader instanceof PluginClassLoader) { if (isBetter.test((PluginClassLoader)loader)) { bestLoader = (PluginClassLoader)loader; } } else if (nonPluginLoader == null) { nonPluginLoader = loader; } } } ClassLoader superLoader = superclass != null ? superclass.getClassLoader() : null; return superLoader instanceof PluginClassLoader && isBetter.test((PluginClassLoader)superLoader) ? superLoader : bestLoader != null ? bestLoader : superLoader != null ? superLoader : nonPluginLoader; }