{"record":{"id":"03e46517694cdad6","repo":"apache/maven","slug":"cannot-create-instance-of-s","errorCode":null,"errorMessage":"Cannot create instance of: %s","messagePattern":"Cannot create instance of: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compat/maven-embedder/src/main/java/org/eclipse/sisu/plexus/PlexusXmlBeanConverter.java","lineNumber":332,"sourceCode":"            return Class.forName(name);\n        } catch (final Exception e) {\n            throw new TypeNotPresentException(name, e);\n        } catch (final LinkageError e) {\n            throw new TypeNotPresentException(name, e);\n        }\n    }\n\n    /**\n     * Creates an instance of the given implementation using the default constructor.\n     *\n     * @param clazz The implementation type\n     * @return Instance of given implementation\n     */\n    private static <T> T newImplementation(final Class<T> clazz) {\n        try {\n            return clazz.newInstance();\n        } catch (final Exception e) {\n            throw new IllegalArgumentException(\"Cannot create instance of: \" + clazz, e);\n        } catch (final LinkageError e) {\n            throw new IllegalArgumentException(\"Cannot create instance of: \" + clazz, e);\n        }\n    }\n\n    /**\n     * Creates an instance of the given implementation using the given string, assumes a public string constructor.\n     *\n     * @param clazz The implementation type\n     * @param value The string argument\n     * @return Instance of given implementation, constructed using the given string\n     */\n    private static <T> T newImplementation(final Class<T> clazz, final String value) {\n        try {\n            return clazz.getConstructor(String.class).newInstance(value);\n        } catch (final Exception e) {\n            final Throwable cause = e instanceof InvocationTargetException ? e.getCause() : e;\n            throw new IllegalArgumentException(String.format(CONVERSION_ERROR, value, clazz), cause);","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-embedder/src/main/java/org/eclipse/sisu/plexus/PlexusXmlBeanConverter.java#L314-L350","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Add a public no-arg constructor to the implementation class","Point implementation= at a concrete subclass instead of an abstract class or interface","Make the constructor public: package-private/private blocks newInstance","Inspect the caused-by exception for failures inside the constructor itself"],"exampleFix":"// before: only a String constructor - default instantiation fails\npublic class Timeout {\n    public Timeout(String millis) { /* ... */ }\n}\n\n// after: add a public no-arg constructor\npublic class Timeout {\n    public Timeout() { this(0); }\n    public Timeout(String millis) { /* ... */ }\n}","handlingStrategy":"validation","validationCode":"// before pointing XML <implementation> at a class, verify it can be instantiated\nClass<?> impl = Class.forName(implementationName);\nif (!instantiableViaNoArg(impl)) {\n    throw new IllegalArgumentException(\"Need a public no-arg constructor: \" + impl.getName());\n}","typeGuard":"static boolean instantiableViaNoArg(Class<?> c) {\n    if (c.isInterface() || Modifier.isAbstract(c.getModifiers())) return false;\n    try {\n        c.getConstructor();\n        return true;\n    } catch (NoSuchMethodException e) {\n        return false;\n    }\n}","tryCatchPattern":null,"preventionTips":["Give every class named in <implementation> a public no-arg constructor","Prefer concrete classes as configurable implementations","Smoke-test instantiation of configurable types at startup"],"tags":["reflection","instantiation","plexus","configuration","constructor"],"backgroundTag":"no-default-constructor","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}