{"record":{"id":"f1a2d8e301a29c22","repo":"apache/cassandra","slug":"error-instantiating-s-class-s","errorCode":null,"errorMessage":"Error instantiating %s class '%s'.","messagePattern":"Error instantiating (.+?) class '(.+?)'\\.","errorType":"exception","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/utils/FBUtilities.java","lineNumber":915,"sourceCode":"    {\n        try\n        {\n            return cls.newInstance();\n        }\n        catch (IllegalAccessException e)\n        {\n            throw new ConfigurationException(String.format(\"Default constructor for %s class '%s' is inaccessible.\", readable, classname));\n        }\n        catch (InstantiationException e)\n        {\n            throw new ConfigurationException(String.format(\"Cannot use abstract class '%s' as %s.\", classname, readable));\n        }\n        catch (Exception e)\n        {\n            // Catch-all because Class.newInstance() \"propagates any exception thrown by the nullary constructor, including a checked exception\".\n            if (e.getCause() instanceof ConfigurationException)\n                throw (ConfigurationException)e.getCause();\n            throw new ConfigurationException(String.format(\"Error instantiating %s class '%s'.\", readable, classname), e);\n        }\n    }\n\n    public static <T> NavigableSet<T> singleton(T column, Comparator<? super T> comparator)\n    {\n        NavigableSet<T> s = new TreeSet<T>(comparator);\n        s.add(column);\n        return s;\n    }\n\n    public static <T> NavigableSet<T> emptySortedSet(Comparator<? super T> comparator)\n    {\n        return new TreeSet<T>(comparator);\n    }\n\n    /**\n     * Make straing out of the given {@code Map}.\n     *","sourceCodeStart":897,"sourceCodeEnd":933,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/utils/FBUtilities.java#L897-L933","documentation":"FBUtilities.classForName/<T>construct instantiates a class by its configured class name via reflection. If instantiation throws any exception whose cause is not a ConfigurationException, it is rethrown as a ConfigurationException with this message. It means a class named in configuration exists and loaded but its constructor failed (or the class could not be instantiated).","triggerScenarios":"Calling FBUtilities.classForName(...).newInstance() or construct() with a class whose no-arg constructor throws (e.g. IAuthenticator, IAuthorizer, SeedProvider, IEndpointSnitch configured in cassandra.yaml whose constructor throws RuntimeException/other checked exceptions).","commonSituations":"Custom authenticator/authorizer/seed provider classes that throw in their constructors, misconfigured dependencies missing at runtime (NoClassDefFoundError wrapped as cause), or wrong constructor signatures after upgrading a plugin.","solutions":["Inspect the wrapped cause exception in the stack trace to find why the class constructor failed","Fix the class's no-arg constructor (throw ConfigurationException directly if the failure is a config problem)","Verify the class and all its dependencies are on the Cassandra classpath (lib/)","Correct the fully-qualified class name in cassandra.yaml if the wrong class is configured"],"exampleFix":"// before: public class MyAuthenticator implements IAuthenticator { public MyAuthenticator() { init(); } }\n// after:  public class MyAuthenticator implements IAuthenticator { public MyAuthenticator() { try { init(); } catch (Exception e) { throw new ConfigurationException(\"init failed: \" + e.getMessage()); } } }","handlingStrategy":"try-catch","validationCode":"try { Class.forName(className).getDeclaredConstructor().newInstance(); } catch (Throwable t) { /* class/ctor problem before config load */ }","typeGuard":null,"tryCatchPattern":"try { T impl = FBUtilities.construct(className, \"authenticator\"); } catch (ConfigurationException e) { logger.error(\"Bad class config: {}\", e.getCause(), e); throw e; }","preventionTips":["Throw ConfigurationException from plugin constructors so the cause is unwrapped","Smoke-test custom plugin classes with a no-arg constructor unit test","Keep plugin jars on the server classpath and verify after upgrades"],"tags":["reflection","configuration","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"}