{"record":{"id":"a2b638aaeed89021","repo":"jenkinsci/jenkins","slug":"unable-to-create-instance-of-from","errorCode":null,"errorMessage":"Unable to create instance of {} from {}","messagePattern":"Unable to create instance of (.+?) from (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/hudson/ClassicPluginStrategy.java","lineNumber":393,"sourceCode":"        ClassLoader old = Thread.currentThread().getContextClassLoader();\n        Thread.currentThread().setContextClassLoader(wrapper.classLoader);\n        try {\n            String className = wrapper.getPluginClass();\n            if (className == null) {\n                // use the default dummy instance\n                wrapper.setPlugin(new DummyImpl());\n            } else {\n                try {\n                    Class<?> clazz = wrapper.classLoader.loadClass(className);\n                    Object o = clazz.getDeclaredConstructor().newInstance();\n                    if (!(o instanceof Plugin)) {\n                        throw new IOException(className + \" doesn't extend from hudson.Plugin\");\n                    }\n                    wrapper.setPlugin((Plugin) o);\n                } catch (LinkageError | ClassNotFoundException e) {\n                    throw new IOException(\"Unable to load \" + className + \" from \" + wrapper.getShortName(), e);\n                } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {\n                    throw new IOException(\"Unable to create instance of \" + className + \" from \" + wrapper.getShortName(), e);\n                }\n            }\n\n            // initialize plugin\n            try {\n                Plugin plugin = wrapper.getPluginOrFail();\n                plugin.setServletContext(pluginManager.context);\n                startPlugin(wrapper);\n            } catch (Throwable t) {\n                // gracefully handle any error in plugin.\n                throw new IOException(\"Failed to initialize\", t);\n            }\n        } finally {\n            Thread.currentThread().setContextClassLoader(old);\n        }\n    }\n\n    public void startPlugin(PluginWrapper plugin) throws Exception {","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/ClassicPluginStrategy.java#L375-L411","documentation":"IOException thrown when the plugin class is found and loaded but cannot be instantiated via reflection (getDeclaredConstructor().newInstance()). Covers NoSuchMethodException (no accessible no-arg constructor), InstantiationException (abstract class), IllegalAccessException (non-public constructor), or InvocationTargetException (constructor threw).","triggerScenarios":"The Plugin-Class lacks a public no-arg constructor, is abstract, or its constructor throws an exception during initialization.","commonSituations":"Plugin class written without a no-arg constructor (only a parameterized one); constructor does heavy work and fails (NPE, missing config); class marked abstract; constructor not public.","solutions":["Add a public no-arg constructor to the Plugin subclass; keep the constructor lightweight and do startup work in start()/postInitialize() instead.","If the constructor threw, inspect the caused-by exception to find the real initialization error and fix it.","Ensure the class is concrete (not abstract) and the constructor is accessible."],"exampleFix":"// before: only a parameterized constructor, no usable no-arg ctor\npublic class MyPlugin extends Plugin {\n  public MyPlugin(Config c) { ... }\n}\n// after: lightweight no-arg constructor, work deferred to start()\npublic class MyPlugin extends Plugin {\n  public MyPlugin() {}\n  @Override public void start() throws Exception { ... }\n}","handlingStrategy":"validation","validationCode":"// Verify a public no-arg constructor exists before instantiation\nConstructor<?> ctor;\ntry {\n    ctor = clazz.getDeclaredConstructor();\n} catch (NoSuchMethodException e) {\n    throw new IOException(className + \" needs a public no-arg constructor\", e);\n}\nif (!Modifier.isPublic(ctor.getModifiers())) {\n    throw new IOException(className + \" no-arg constructor must be public\");\n}","typeGuard":"boolean hasPublicNoArgCtor(Class<?> c) {\n    try {\n        return Modifier.isPublic(c.getDeclaredConstructor().getModifiers());\n    } catch (NoSuchMethodException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    Object o = clazz.getDeclaredConstructor().newInstance();\n} catch (InvocationTargetException e) {\n    // inspect e.getCause() for the real constructor failure\n} catch (NoSuchMethodException | InstantiationException | IllegalAccessException e) {\n    // add/fix the public no-arg constructor\n}","preventionTips":["Always provide a public no-arg constructor on Plugin subclasses.","Do heavy initialization in start()/postInitialize(), not the constructor.","Write a smoke test that instantiates the Plugin class."],"tags":["jenkins","plugin-loading","instantiation","reflection"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}