{"record":{"id":"4722246f1b9b427f","repo":"apache/cassandra","slug":"no-valid-constructor-found-for-class-class-name","errorCode":null,"errorMessage":"No valid constructor found for class <class_name>","messagePattern":"No valid constructor found for class <class_name>","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/ParameterizedClass.java","lineNumber":128,"sourceCode":"        // Verify the resolved class is the expected extension type before it is initialized/instantiated. Done once,\n        // after the package search, so a wrong-type match under an earlier search package does not abort the search\n        // before a valid class under a later package is found.\n        if (expectedType != null && !expectedType.isAssignableFrom(providerClass))\n            throw new ConfigurationException(\"Invalid parameterized class \" + providerClass.getName() +\n                                             \": must extend or implement \" + expectedType.getName());\n\n        try\n        {\n            Constructor<?> mapConstructor = filterConstructor(providerClass, c -> c.getParameterTypes().length == 1 && c.getParameterTypes()[0].equals(Map.class));\n            if (mapConstructor != null)\n                return (K) mapConstructor.newInstance(parameterizedClass.parameters == null ? Collections.emptyMap() : parameterizedClass.parameters);\n\n            // Falls-back to no-arg constructor\n            Constructor<?> noArgsConstructor = filterConstructor(providerClass, c -> c.getParameterTypes().length == 0);\n            if (noArgsConstructor != null)\n                return (K) noArgsConstructor.newInstance();\n\n            throw new ConfigurationException(\"No valid constructor found for class \" + parameterizedClass.class_name);\n        }\n        catch (IllegalAccessException | InstantiationException | ExceptionInInitializerError e)\n        {\n            throw new ConfigurationException(\"Unable to instantiate parameterized class \" + parameterizedClass.class_name, e);\n        }\n        catch (InvocationTargetException e)\n        {\n            Throwable cause = e.getCause();\n            String error = \"Failed to instantiate class \" + parameterizedClass.class_name +\n                           (cause.getMessage() != null ? \": \" + cause.getMessage() : \"\");\n            throw new ConfigurationException(error, cause);\n        }\n    }\n\n    private static Constructor<?> filterConstructor(Class<?> providerClass, Predicate<Constructor<?>> filter)\n    {\n        for (Constructor<?> constructor : providerClass.getDeclaredConstructors())\n        {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/ParameterizedClass.java#L110-L146","documentation":"ParameterizedClass.newInstance() reflectively instantiates a configured provider/impl class from its class_name. After trying constructors matching the configured parameters and then the no-arg constructor, if none can be found it throws ConfigurationException. It means the configured class exists but exposes no constructor Cassandra can call.","triggerScenarios":"Setting a config key like commitlog_sync, key_cache_size, or a custom provider class_name to a class that has no no-arg constructor and no constructor matching the supplied parameters.","commonSituations":"Implementing a custom ICommitLogWrite/encryption provider with only a parameterized constructor; renaming constructors to require arguments; pointing class_name at an abstract class or interface with no usable constructor.","solutions":["Add a public no-arg constructor to the configured class","Ensure any required parameters in the ParameterizedClass map match a declared constructor's parameter types","Verify the class_name points at a concrete, instantiable class (not abstract/interface)","Check the fully-qualified class name is correct and the class is on the classpath"],"exampleFix":"// before\npublic class MyProvider implements IProvider {\n    public MyProvider(String requiredArg) { ... }\n}\n// after\npublic class MyProvider implements IProvider {\n    public MyProvider() { ... }\n    public MyProvider(String requiredArg) { ... }\n}","handlingStrategy":"validation","validationCode":"Class<?> c = Class.forName(className);\nboolean ok = !c.isInterface() && !java.lang.reflect.Modifier.isAbstract(c.getModifiers())\n    && java.util.Arrays.stream(c.getDeclaredConstructors())\n        .anyMatch(k -> k.getParameterCount() == 0);\nif (!ok) throw new IllegalStateException(className + \" needs a public no-arg constructor\");","typeGuard":"static boolean hasUsableConstructor(String className) {\n    try {\n        Class<?> c = Class.forName(className);\n        return !c.isInterface() && !java.lang.reflect.Modifier.isAbstract(c.getModifiers())\n            && java.util.Arrays.stream(c.getDeclaredConstructors())\n                .anyMatch(k -> k.getParameterCount() == 0);\n    } catch (ClassNotFoundException e) { return false; }\n}","tryCatchPattern":"try { K instance = ParameterizedClass.newInstance(cls); }\ncatch (ConfigurationException e) { log.error(\"Bad provider class: \" + e.getMessage()); throw e; }","preventionTips":["Always provide a public no-arg constructor in provider classes","Keep provider classes concrete (non-abstract, public)","Test custom provider classes load standalone before deploying"],"tags":["configuration","reflection","class-instantiation"],"backgroundTag":"class-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}