{"record":{"id":"656a288a60321820","repo":"apache/cassandra","slug":"failed-to-instantiate-class-class-name-cause-g","errorCode":null,"errorMessage":"Failed to instantiate class <class_name>: <cause.getMessage()>","messagePattern":"Failed to instantiate class <class_name>: <cause\\.getMessage\\(\\)>","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/ParameterizedClass.java","lineNumber":139,"sourceCode":"                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        {\n            if (filter.test(constructor))\n                return constructor;\n        }\n\n        return null;\n    }\n\n    @Override\n    public boolean equals(Object that)\n    {\n        return that instanceof ParameterizedClass && equals((ParameterizedClass) that);","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/ParameterizedClass.java#L121-L157","documentation":"Thrown when the selected constructor of the configured parameterized class itself threw an exception (InvocationTargetException). The message wraps the underlying cause's message, so the real failure reason comes from the configured class's own constructor code.","triggerScenarios":"A provider class configured via class_name whose constructor throws at runtime — e.g. fails to read a keystore, connect to KMS, validate parameters, or any other RuntimeException/Error raised during construction.","commonSituations":"Custom encryption/commitlog providers that open files or network resources in their constructor and fail on bad config; constructor argument validation failures; missing external resources in the deployment environment.","solutions":["Read the wrapped cause message — it is the exception thrown by the class's own constructor","Fix the underlying failure in the configured class's constructor (bad args, missing file, connection failure)","Add defensive validation in the constructor to fail with a clear message","Test the provider class standalone before wiring it into cassandra.yaml"],"exampleFix":"// before\npublic MyProvider() { open(keystorePath); } // NPE if null\n// after\npublic MyProvider() {\n    if (keystorePath == null) throw new ConfigurationException(\"keystore_path must be set\");\n    open(keystorePath);\n}","handlingStrategy":"try-catch","validationCode":"// smoke-test the constructor before wiring config\nObject o = Class.forName(className).getDeclaredConstructor().newInstance();\nassert o != null;","typeGuard":null,"tryCatchPattern":"try { K instance = ParameterizedClass.newInstance(cls); }\ncatch (ConfigurationException e) {\n    // e.getCause() is the exception the constructor itself threw\n    log.error(\"Provider {} failed in constructor: {}\", className, e.getCause().getMessage(), e);\n}","preventionTips":["Validate constructor inputs early with clear messages","Avoid file/network I/O failures in constructors — lazy-init where possible","Test provider construction in the target environment before rollout"],"tags":["configuration","reflection","constructor-exception"],"backgroundTag":"invalid-config-value","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"}