apache/maven · error · IllegalArgumentException

Cannot create instance of: %s

Error message

Cannot create instance of: %s

What it means

PlexusXmlBeanConverter.newImplementation(Class) instantiates the implementation named in XML via its public no-arg constructor (Class.newInstance). This IllegalArgumentException covers the reflective Exception branch: the constructor is missing, non-public, or threw, so the configured implementation cannot be created.

Source

Thrown at compat/maven-embedder/src/main/java/org/eclipse/sisu/plexus/PlexusXmlBeanConverter.java:332

            return Class.forName(name);
        } catch (final Exception e) {
            throw new TypeNotPresentException(name, e);
        } catch (final LinkageError e) {
            throw new TypeNotPresentException(name, e);
        }
    }

    /**
     * Creates an instance of the given implementation using the default constructor.
     *
     * @param clazz The implementation type
     * @return Instance of given implementation
     */
    private static <T> T newImplementation(final Class<T> clazz) {
        try {
            return clazz.newInstance();
        } catch (final Exception e) {
            throw new IllegalArgumentException("Cannot create instance of: " + clazz, e);
        } catch (final LinkageError e) {
            throw new IllegalArgumentException("Cannot create instance of: " + clazz, e);
        }
    }

    /**
     * Creates an instance of the given implementation using the given string, assumes a public string constructor.
     *
     * @param clazz The implementation type
     * @param value The string argument
     * @return Instance of given implementation, constructed using the given string
     */
    private static <T> T newImplementation(final Class<T> clazz, final String value) {
        try {
            return clazz.getConstructor(String.class).newInstance(value);
        } catch (final Exception e) {
            final Throwable cause = e instanceof InvocationTargetException ? e.getCause() : e;
            throw new IllegalArgumentException(String.format(CONVERSION_ERROR, value, clazz), cause);

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Add a public no-arg constructor to the implementation class
  2. Point implementation= at a concrete subclass instead of an abstract class or interface
  3. Make the constructor public: package-private/private blocks newInstance
  4. Inspect the caused-by exception for failures inside the constructor itself

Example fix

// before: only a String constructor - default instantiation fails
public class Timeout {
    public Timeout(String millis) { /* ... */ }
}

// after: add a public no-arg constructor
public class Timeout {
    public Timeout() { this(0); }
    public Timeout(String millis) { /* ... */ }
}
Defensive patterns

Strategy: validation

Validate before calling

// before pointing XML <implementation> at a class, verify it can be instantiated
Class<?> impl = Class.forName(implementationName);
if (!instantiableViaNoArg(impl)) {
    throw new IllegalArgumentException("Need a public no-arg constructor: " + impl.getName());
}

Type guard

static boolean instantiableViaNoArg(Class<?> c) {
    if (c.isInterface() || Modifier.isAbstract(c.getModifiers())) return false;
    try {
        c.getConstructor();
        return true;
    } catch (NoSuchMethodException e) {
        return false;
    }
}

Prevention

When it happens

Trigger: XML configuration selects an implementation (via <implementation> element or the default class) that is abstract, an interface, lacks a public no-arg constructor, or whose constructor throws during instantiation.

Common situations: Configuring a class that only has String or argument constructors; naming an abstract base as implementation; constructors performing initialization that fails (missing env var, null context).

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/03e46517694cdad6. Report an issue: GitHub.