{"record":{"id":"9c283e1b98d851a7","repo":"SonarSource/sonarqube","slug":"fail-to-create-classloader-for-plugin-s","errorCode":null,"errorMessage":"Fail to create classloader for plugin [%s]","messagePattern":"Fail to create classloader for plugin \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"sonar-core/src/main/java/org/sonar/core/platform/PluginClassloaderFactory.java","lineNumber":112,"sourceCode":"    // export the resources to all other plugins\n    builder.setExportMask(newDef.getBasePluginKey(), newDef.getExportMask().build());\n    for (PluginClassLoaderDef other : allPlugins) {\n      if (!other.getBasePluginKey().equals(newDef.getBasePluginKey())) {\n        builder.addSibling(newDef.getBasePluginKey(), other.getBasePluginKey(), Mask.ALL);\n      }\n    }\n  }\n\n  /**\n   * Builds classloaders and verifies that all of them are correctly defined\n   */\n  private static Map<PluginClassLoaderDef, ClassLoader> build(Collection<PluginClassLoaderDef> defs, ClassloaderBuilder builder) {\n    Map<PluginClassLoaderDef, ClassLoader> result = new HashMap<>();\n    Map<String, ClassLoader> classloadersByBasePluginKey = builder.build();\n    for (PluginClassLoaderDef def : defs) {\n      ClassLoader classloader = classloadersByBasePluginKey.get(def.getBasePluginKey());\n      if (classloader == null) {\n        throw new IllegalStateException(String.format(\"Fail to create classloader for plugin [%s]\", def.getBasePluginKey()));\n      }\n      result.put(def, classloader);\n    }\n    return result;\n  }\n\n  ClassLoader baseClassLoader() {\n    return getClass().getClassLoader();\n  }\n\n  private static URL fileToUrl(File file) {\n    try {\n      return file.toURI().toURL();\n    } catch (MalformedURLException e) {\n      throw new IllegalArgumentException(e);\n    }\n  }\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-core/src/main/java/org/sonar/core/platform/PluginClassloaderFactory.java#L94-L130","documentation":"SonarQube's PluginClassloaderFactory throws this IllegalStateException during plugin classloader construction when a plugin classloader definition references a basePluginKey for which no classloader exists in the built map. This means the definition depends on a base plugin that is not loaded (missing, unloaded, or wrong key). It is an internal invariant check guarding the plugin isolation/isolation-by-key loading model.","triggerScenarios":"Calling PluginClassloaderFactory.create() with PluginClassLoaderDef entries whose getBasePluginKey() is absent from the map returned by the ClassloaderBuilder.build() (e.g. a plugin declares a dependency on a base plugin that is not installed or failed to load).","commonSituations":"A plugin requiring a base plugin (like 'api' from a sonar-plugin dependency) that was removed from the plugins directory; corrupted plugin ordering; a plugin renamed/re-keyed so dependent plugins point at a stale key.","solutions":["Verify the base plugin referenced by the failing plugin key is present in the plugins directory and listed in the loaded plugins.","Check startup logs for earlier plugin load failures that removed the base plugin before classloader construction.","Ensure the plugin's build declares the basePluginKey consistently (plugin key in its sonar-plugin packaging descriptor).","Upgrade or reinstall the dependent plugin to a version compatible with the installed SonarQube version."],"exampleFix":"// before (definition references missing base plugin)\nnew PluginClassLoaderDef(\"my-plugin\", \"nonexistent-base\", ...);\n// after\nnew PluginClassLoaderDef(\"my-plugin\", \"base-plugin-key\", ...); // key must exist among loaded plugins","handlingStrategy":"validation","validationCode":"Set<String> loadedKeys = builder.build().keySet();\nfor (PluginClassLoaderDef def : defs) {\n  if (!loadedKeys.contains(def.getBasePluginKey())) {\n    throw new IllegalArgumentException(\"Base plugin not loaded: \" + def.getBasePluginKey());\n  }\n}","typeGuard":null,"tryCatchPattern":"// IllegalStateException is unchecked; pre-validate base plugin keys before create()\ntry {\n  factory.create(defs);\n} catch (IllegalStateException e) {\n  log.error(\"Plugin dependency missing: {}\", e.getMessage());\n}","preventionTips":["Keep all required base plugins installed alongside dependent plugins.","Check startup logs for plugin load failures before classloader construction.","Pin plugin versions compatible with your SonarQube release."],"tags":["plugin-loading","classloader","illegal-state"],"backgroundTag":"missing-dependency","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}