jenkinsci/jenkins · error · IOException

Unable to create instance of {} from {}

Error message

Unable to create instance of {} from {}

What it means

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).

Source

Thrown at core/src/main/java/hudson/ClassicPluginStrategy.java:393

        ClassLoader old = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(wrapper.classLoader);
        try {
            String className = wrapper.getPluginClass();
            if (className == null) {
                // use the default dummy instance
                wrapper.setPlugin(new DummyImpl());
            } else {
                try {
                    Class<?> clazz = wrapper.classLoader.loadClass(className);
                    Object o = clazz.getDeclaredConstructor().newInstance();
                    if (!(o instanceof Plugin)) {
                        throw new IOException(className + " doesn't extend from hudson.Plugin");
                    }
                    wrapper.setPlugin((Plugin) o);
                } catch (LinkageError | ClassNotFoundException e) {
                    throw new IOException("Unable to load " + className + " from " + wrapper.getShortName(), e);
                } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
                    throw new IOException("Unable to create instance of " + className + " from " + wrapper.getShortName(), e);
                }
            }

            // initialize plugin
            try {
                Plugin plugin = wrapper.getPluginOrFail();
                plugin.setServletContext(pluginManager.context);
                startPlugin(wrapper);
            } catch (Throwable t) {
                // gracefully handle any error in plugin.
                throw new IOException("Failed to initialize", t);
            }
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }
    }

    public void startPlugin(PluginWrapper plugin) throws Exception {

View on GitHub (pinned to 2e228ff40b)

Solutions

  1. Add a public no-arg constructor to the Plugin subclass; keep the constructor lightweight and do startup work in start()/postInitialize() instead.
  2. If the constructor threw, inspect the caused-by exception to find the real initialization error and fix it.
  3. Ensure the class is concrete (not abstract) and the constructor is accessible.

Example fix

// before: only a parameterized constructor, no usable no-arg ctor
public class MyPlugin extends Plugin {
  public MyPlugin(Config c) { ... }
}
// after: lightweight no-arg constructor, work deferred to start()
public class MyPlugin extends Plugin {
  public MyPlugin() {}
  @Override public void start() throws Exception { ... }
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify a public no-arg constructor exists before instantiation
Constructor<?> ctor;
try {
    ctor = clazz.getDeclaredConstructor();
} catch (NoSuchMethodException e) {
    throw new IOException(className + " needs a public no-arg constructor", e);
}
if (!Modifier.isPublic(ctor.getModifiers())) {
    throw new IOException(className + " no-arg constructor must be public");
}

Type guard

boolean hasPublicNoArgCtor(Class<?> c) {
    try {
        return Modifier.isPublic(c.getDeclaredConstructor().getModifiers());
    } catch (NoSuchMethodException e) {
        return false;
    }
}

Try / catch

try {
    Object o = clazz.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException e) {
    // inspect e.getCause() for the real constructor failure
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException e) {
    // add/fix the public no-arg constructor
}

Prevention

When it happens

Trigger: The Plugin-Class lacks a public no-arg constructor, is abstract, or its constructor throws an exception during initialization.

Common situations: 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.

Related errors


AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14). Data as JSON: /api/errors/a2b638aaeed89021. Report an issue: GitHub.