{"record":{"id":"f5df0bc6ac9dedd1","repo":"apache/cassandra","slug":"unable-to-instantiate-parameterized-class-class-n","errorCode":null,"errorMessage":"Unable to instantiate parameterized class <class_name>","messagePattern":"Unable to instantiate parameterized class <class_name>","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/config/ParameterizedClass.java","lineNumber":132,"sourceCode":"            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        {\n            if (filter.test(constructor))\n                return constructor;\n        }\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/config/ParameterizedClass.java#L114-L150","documentation":"Thrown when reflective instantiation of the configured parameterized class fails with IllegalAccessException, InstantiationException, or ExceptionInInitializerError. The class was found and a constructor selected, but invoking it failed — e.g. the constructor is not accessible, the class is abstract, or its static initializer threw.","triggerScenarios":"Configured class_name refers to an abstract class or interface (InstantiationException), a non-public class/constructor without accessibility (IllegalAccessException), or a class whose static init block throws (ExceptionInInitializerError).","commonSituations":"Custom provider classes written package-private or with private constructors; classes that throw in static initializers due to bad environment or missing dependencies; pointing config at abstract base classes.","solutions":["Make the class and its used constructor public and concrete (non-abstract)","Inspect the cause (attached to this ConfigurationException) for the underlying InstantiationException/ExceptionInInitializerError","Fix any exception thrown in the class's static initializer","Ensure the class is loadable in the Cassandra JVM (correct jar on classpath)"],"exampleFix":"// before\nclass MyProvider implements IProvider { ... } // package-private\n// after\npublic class MyProvider implements IProvider {\n    public MyProvider() { ... }\n}","handlingStrategy":"try-catch","validationCode":"Class<?> c = Class.forName(className);\nif (java.lang.reflect.Modifier.isAbstract(c.getModifiers()) || c.isInterface())\n    throw new IllegalStateException(className + \" must be a concrete public class\");","typeGuard":"static boolean isInstantiable(String className) {\n    try {\n        Class<?> c = Class.forName(className);\n        int m = c.getModifiers();\n        return !c.isInterface() && !java.lang.reflect.Modifier.isAbstract(m) && java.lang.reflect.Modifier.isPublic(m);\n    } catch (Throwable t) { return false; }\n}","tryCatchPattern":"try { K instance = ParameterizedClass.newInstance(cls); }\ncatch (ConfigurationException e) {\n    // e.getCause() holds InstantiationException / IllegalAccessException / ExceptionInInitializerError\n    log.error(\"Cannot instantiate {}: {}\", className, e.getCause(), e);\n}","preventionTips":["Make custom providers public with public constructors","Avoid heavy logic in static initializers","Ensure all jars providing provider classes ship with the deployment"],"tags":["configuration","reflection","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"}