{"record":{"id":"e712937ebef14b62","repo":"jenkinsci/jenkins","slug":"cannot-find-the-plugin-instance-0","errorCode":null,"errorMessage":"Cannot find the plugin instance: {0}","messagePattern":"Cannot find the plugin instance: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"core/src/main/java/hudson/PluginWrapper.java","lineNumber":619,"sourceCode":"    }\n\n    /**\n     * Gets the instance of {@link Plugin} contributed by this plugin.\n     * @return Plugin instace or {@code null} if it is not present in the plugin instance store.\n     */\n    public @CheckForNull Plugin getPlugin() {\n        PluginInstanceStore pis = Jenkins.lookup(PluginInstanceStore.class);\n        return pis != null ? pis.store.get(this) : null;\n    }\n\n    /**\n     * Gets the instance of {@link Plugin} contributed by this plugin.\n     * @throws Exception no plugin in the {@link PluginInstanceStore}\n     */\n    public @NonNull Plugin getPluginOrFail() throws Exception {\n        Plugin plugin = getPlugin();\n        if (plugin == null) {\n            throw new Exception(\"Cannot find the plugin instance: \" + shortName);\n        }\n        return plugin;\n    }\n\n    /**\n     * Gets the URL that shows more information about this plugin.\n     * @return\n     *      null if this information is unavailable.\n     * @since 1.283\n     */\n    @Exported\n    public String getUrl() {\n        // first look in update center metadata\n        List<UpdateSite.Plugin> siteMetadataList = getInfoFromAllSites();\n        String firstSiteUrl = null;\n        if (!siteMetadataList.isEmpty()) {\n            firstSiteUrl = siteMetadataList.getFirst().wiki;\n            if (allUrlsMatch(firstSiteUrl, siteMetadataList)) {","sourceCodeStart":601,"sourceCodeEnd":637,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/PluginWrapper.java#L601-L637","documentation":"Exception thrown by getPluginOrFail() when the PluginInstanceStore does not contain a Plugin instance for this PluginWrapper. This means the plugin's Java instance (the Plugin subclass) was never registered — the plugin loaded structurally (classloader, manifest) but its Plugin.start()/onLoad() either failed or never ran, or the PluginInstanceStore was not populated.","triggerScenarios":"Calling pluginWrapper.getPluginOrFail() when the plugin's Plugin instance has not been registered in the PluginInstanceStore — typically during early initialization before the plugin's start() completes, or after a failed initialization.","commonSituations":"A plugin whose constructor or onLoad() threw an exception (so the instance was never stored), calling postInitialize before the plugin is fully started, or accessing the plugin instance during a partial/failed load cycle.","solutions":["Check pluginWrapper.getPlugin() for null before calling getPluginOrFail().","Review Jenkins logs for errors during the plugin's onLoad()/start() lifecycle.","Ensure the plugin's Plugin subclass is properly annotated and instantiated by the extension framework.","Restart Jenkins if the plugin is in a partially loaded state."],"exampleFix":"// before\nPlugin plugin = wrapper.getPluginOrFail();\nplugin.doSomething();\n\n// after\nPlugin plugin = wrapper.getPlugin();\nif (plugin == null) {\n    listener.getLogger().println(\"Plugin \" + wrapper.getShortName() + \" not initialized.\");\n    return;\n}\nplugin.doSomething();","handlingStrategy":"validation","validationCode":"Plugin plugin = wrapper.getPlugin();\nif (plugin == null) {\n    throw new IllegalStateException(\"Plugin instance for \" + wrapper.getShortName() + \" not initialized; check Jenkins logs for startup errors.\");\n}","typeGuard":"public static boolean isPluginInitialized(PluginWrapper pw) {\n    return pw.getPlugin() != null;\n}","tryCatchPattern":"try {\n    Plugin plugin = wrapper.getPluginOrFail();\n    plugin.doSomething();\n} catch (Exception e) {\n    if (e.getMessage().contains(\"Cannot find the plugin instance\")) {\n        listener.getLogger().println(\"Plugin \" + wrapper.getShortName() + \" not initialized; skipping.\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Use getPlugin() (null-safe) instead of getPluginOrFail() when the instance may not be available.","Review Jenkins startup logs for plugin initialization failures.","Ensure the plugin's Plugin subclass is properly registered via @Extension or manifest."],"tags":["plugin-wrapper","lifecycle","initialization","plugin-instance"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}