{"record":{"id":"971854c73c6c3a72","repo":"alibaba/canal","slug":"extension-instance-name-class-could-not-971854","errorCode":null,"errorMessage":"Extension instance(name: {}, class: {})  could not be instantiated: {}","messagePattern":"Extension instance\\(name: (.+?), class: (.+?)\\)  could not be instantiated: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"connector/core/src/main/java/com/alibaba/otter/canal/connector/core/spi/ExtensionLoader.java","lineNumber":180,"sourceCode":"        return getExtension(cachedDefaultName, spiDir, standbyDir);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    public T createExtension(String name, String spiDir, String standbyDir) {\n        Class<?> clazz = getExtensionClasses(spiDir, standbyDir).get(name);\n        if (clazz == null) {\n            throw new IllegalStateException(\"Extension instance(name: \" + name + \", class: \" + type\n                                            + \")  could not be instantiated: class could not be found\");\n        }\n        try {\n            T instance = (T) EXTENSION_INSTANCES.get(clazz);\n            if (instance == null) {\n                EXTENSION_INSTANCES.putIfAbsent(clazz, (T) clazz.newInstance());\n                instance = (T) EXTENSION_INSTANCES.get(clazz);\n            }\n            return instance;\n        } catch (Throwable t) {\n            throw new IllegalStateException(\"Extension instance(name: \" + name + \", class: \" + type\n                                            + \")  could not be instantiated: \" + t.getMessage(), t);\n        }\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private T createExtension(String name, String key, String spiDir, String standbyDir) {\n        Class<?> clazz = getExtensionClasses(spiDir, standbyDir).get(name);\n        if (clazz == null) {\n            throw new IllegalStateException(\"Extension instance(name: \" + name + \", class: \" + type\n                                            + \")  could not be instantiated: class could not be found\");\n        }\n        try {\n            T instance = (T) EXTENSION_KEY_INSTANCE.get(name + \"-\" + key);\n            if (instance == null) {\n                EXTENSION_KEY_INSTANCE.putIfAbsent(name + \"-\" + key, clazz.newInstance());\n                instance = (T) EXTENSION_KEY_INSTANCE.get(name + \"-\" + key);\n            }\n            return instance;","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/connector/core/src/main/java/com/alibaba/otter/canal/connector/core/spi/ExtensionLoader.java#L162-L198","documentation":"Thrown by createExtension(name, spiDir, standbyDir) when clazz.newInstance() (or the ConcurrentHashMap put) throws — e.g. the implementation class has no public no-arg constructor, is abstract, or its constructor threw an exception. The throwable's message is appended. This indicates the extension class was found but could not be instantiated.","triggerScenarios":"The SPI implementation class lacks an accessible public no-arg constructor; the constructor threw (NPE on a required field, failed inner resource init, security manager denial); the class is abstract or an array/primitive.","commonSituations":"Custom extension whose constructor depends on config not yet available; constructor performs network/resource init that fails; class was shaded/obfuscated removing the public constructor; Java 9+ module access restrictions.","solutions":["Ensure the implementation has a public no-arg constructor.","Move constructor side-effects (connection, config reads) into an init/start lifecycle method rather than the constructor.","Inspect the wrapped cause (t.getMessage()/getCause()) for the real instantiation failure and fix that.","If using a custom jar, confirm it is not obfuscated in a way that hides the constructor."],"exampleFix":"// before\npublic class MyProducer implements CanalMQProducer {\n    public MyProducer(Config cfg) { ... }   // no no-arg ctor\n}\n// after\npublic class MyProducer implements CanalMQProducer {\n    public MyProducer() { }                 // SPI instantiates this\n    public void init(Config cfg) { ... }    // called after\n}","handlingStrategy":"try-catch","validationCode":"// Validate the implementation has a public no-arg ctor before requesting\nClass<?> impl = resolveImplClass(interfaceType, name);\nif (impl != null) {\n    try { impl.getConstructor(); }\n    catch (NoSuchMethodException nsme) {\n        throw new IllegalStateException(impl + \" needs a public no-arg constructor\");\n    }\n}","typeGuard":"boolean isInstantiableSpi(Class<?> impl) {\n    try {\n        return impl != null && !Modifier.isAbstract(impl.getModifiers())\n            && impl.getConstructor() != null;\n    } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    return loader.getExtension(name, spiDir, standbyDir);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"could not be instantiated\")) {\n        Throwable c = e.getCause();\n        // inspect c: add no-arg ctor or move init out of constructor\n    }\n    throw e;\n}","preventionTips":["Give SPI implementations a public no-arg constructor.","Keep constructors side-effect-free; do resource init in a start/init method."],"tags":["spi","instantiation","extension-loader"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}