{"record":{"id":"5a21322324fd4208","repo":"SonarSource/sonarqube","slug":"fail-to-instantiate-class-s-of-plugin-s","errorCode":null,"errorMessage":"Fail to instantiate class [%s] of plugin [%s]","messagePattern":"Fail to instantiate class \\[(.+?)\\] of plugin \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoader.java","lineNumber":139,"sourceCode":"   * @throws IllegalStateException if at least one plugin can't be correctly loaded\n   */\n  private static Map<String, Plugin> instantiatePluginClasses(Map<PluginClassLoaderDef, ClassLoader> classloaders) {\n    // instantiate plugins\n    Map<String, Plugin> instancesByPluginKey = new HashMap<>();\n    for (Map.Entry<PluginClassLoaderDef, ClassLoader> entry : classloaders.entrySet()) {\n      PluginClassLoaderDef def = entry.getKey();\n      ClassLoader classLoader = entry.getValue();\n\n      // the same classloader can be used by multiple plugins\n      for (Map.Entry<String, String> mainClassEntry : def.getMainClassesByPluginKey().entrySet()) {\n        String pluginKey = mainClassEntry.getKey();\n        String mainClass = mainClassEntry.getValue();\n        try {\n          instancesByPluginKey.put(pluginKey, (Plugin) classLoader.loadClass(mainClass).getDeclaredConstructor().newInstance());\n        } catch (UnsupportedClassVersionError e) {\n          throw new IllegalStateException(String.format(\"The plugin [%s] does not support Java %s\", pluginKey, SystemUtils.JAVA_VERSION), e);\n        } catch (Throwable e) {\n          throw new IllegalStateException(String.format(\"Fail to instantiate class [%s] of plugin [%s]\", mainClass, pluginKey), e);\n        }\n      }\n    }\n    return instancesByPluginKey;\n  }\n\n  public void unload(Collection<Plugin> plugins) {\n    for (Plugin plugin : plugins) {\n      ClassLoader classLoader = plugin.getClass().getClassLoader();\n      if (classLoader instanceof Closeable closeable && classLoader != classloaderFactory.baseClassLoader()) {\n        try {\n          closeable.close();\n        } catch (Exception e) {\n          LoggerFactory.getLogger(getClass()).error(\"Fail to close classloader \" + classLoader.toString(), e);\n        }\n      }\n    }\n  }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoader.java#L121-L157","documentation":"PluginClassLoader catches any Throwable other than UnsupportedClassVersionError during plugin main-class instantiation and wraps it in an IllegalStateException \"Fail to instantiate class [%s] of plugin [%s]\".","triggerScenarios":"loadClass or newInstance() throws — missing main class (CNFE), constructor exception, NoClassDefFoundError for a missing dependency, security manager denial.","commonSituations":"Corrupted plugin jar; plugin main class constructor throws on bad configuration; missing transitive dependencies; plugin incompatible with platform API.","solutions":["Read the wrapped cause for the root failure (CNFE, NoSuchMethodError, etc.)","Reinstall the plugin jar (verify checksum and completeness)","Update the plugin to a version compatible with the platform","Check plugin configuration properties required by its constructor"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  instances = pluginClassLoader.load(def);\n} catch (IllegalStateException e) {\n  LOG.error(\"Plugin {} failed to load, skipping\", pluginKey, e.getCause());\n  // disable plugin and continue startup if platform allows\n}","preventionTips":["Verify plugin jar integrity after download","Keep plugin and platform versions compatible","Capture and inspect the wrapped cause to diagnose missing dependencies"],"tags":["plugins","instantiation","compatibility"],"backgroundTag":"class-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}