{"record":{"id":"3b5ed26562d447e5","repo":"alibaba/canal","slug":"extension-instance-name-name-class-type-3b5ed2","errorCode":null,"errorMessage":"Extension instance(name: ${name}, class: ${type})  could not be instantiated: ${t.getMessage()}","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":200,"sourceCode":"        }\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;\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    private Map<String, Class<?>> getExtensionClasses(String spiDir, String standbyDir) {\n        Map<String, Class<?>> classes = cachedClasses.get();\n        if (classes == null) {\n            synchronized (cachedClasses) {\n                classes = cachedClasses.get();\n                if (classes == null) {\n                    classes = loadExtensionClasses(spiDir, standbyDir);\n                    cachedClasses.set(classes);\n                }\n            }\n        }\n\n        return classes;\n    }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/connector/core/src/main/java/com/alibaba/otter/canal/connector/core/spi/ExtensionLoader.java#L182-L218","documentation":"Thrown by the private 4-arg createExtension(name, key,...) when the keyed instance cannot be instantiated — clazz.newInstance() threw. Same as 210 but on the per-key path (instance stored under EXTENSION_KEY_INSTANCE keyed by name+key).","triggerScenarios":"The implementation class for a keyed extension has no public no-arg constructor or its constructor threw; abstract class; access restriction.","commonSituations":"Custom per-key extension whose constructor fails; constructor depends on per-key config not yet bound; obfuscation/security constraints.","solutions":["Add a public no-arg constructor to the implementation.","Move per-key init out of the constructor into an init(key) method invoked after instantiation.","Read the wrapped cause to identify the underlying instantiation error and fix it."],"exampleFix":"// before\npublic MyProducer(String key) { this.key = key; }\n// after\npublic MyProducer() { }\npublic void init(String key) { this.key = key; }","handlingStrategy":"try-catch","validationCode":"// Validate keyed impl instantiability\nClass<?> impl = resolveImplClass(interfaceType, name);\ntry { if (impl != null) impl.getConstructor(); }\ncatch (NoSuchMethodException e) {\n    throw new IllegalStateException(impl + \" needs a public no-arg constructor for keyed SPI\");\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, key, spiDir, standbyDir);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"could not be instantiated\")) {\n        Throwable c = e.getCause();\n        // ensure public no-arg ctor; move per-key init out of constructor\n    }\n    throw e;\n}","preventionTips":["Ensure keyed implementations have a public no-arg constructor.","Bind per-key state via an init(key) method, not the constructor."],"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"}