{"record":{"id":"d6e65e6bf760b829","repo":"apache/incubator-seata","slug":"extension-instance-definition-class-cou","errorCode":null,"errorMessage":"Extension instance(definition: {}, class: {})  could not be instantiated: {}","messagePattern":"Extension instance\\(definition: (.+?), class: (.+?)\\)  could not be instantiated: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/org/apache/seata/common/loader/EnhancedServiceLoader.java","lineNumber":499,"sourceCode":"                        if (instance == null) {\n                            instance = createNewExtension(definition, loader, argTypes, args);\n                            holder.set(instance);\n                        }\n                    }\n                }\n                return (S) instance;\n            } else {\n                return createNewExtension(definition, loader, argTypes, args);\n            }\n        }\n\n        private S createNewExtension(\n                ExtensionDefinition<S> definition, ClassLoader loader, Class<?>[] argTypes, Object[] args) {\n            Class<S> clazz = definition.getServiceClass();\n            try {\n                return initInstance(clazz, argTypes, args);\n            } catch (Throwable t) {\n                throw new IllegalStateException(\n                        \"Extension instance(definition: \" + definition + \", class: \" + type\n                                + \")  could not be instantiated: \" + t.getMessage(),\n                        t);\n            }\n        }\n\n        private List<Class<S>> loadAllExtensionClass(ClassLoader loader, boolean includeCompatible) {\n            List<ExtensionDefinition<S>> definitions = definitionsHolder.get();\n            if (definitions == null) {\n                synchronized (definitionsHolder) {\n                    definitions = definitionsHolder.get();\n                    if (definitions == null) {\n                        definitions = findAllExtensionDefinition(loader, includeCompatible);\n                        definitionsHolder.set(definitions);\n                    }\n                }\n            }\n            return definitions.stream()","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/apache/incubator-seata/blob/e01f97c6db397165050caa6764020410c2c8199a/common/src/main/java/org/apache/seata/common/loader/EnhancedServiceLoader.java#L481-L517","documentation":"createNewExtension reflectively instantiates an SPI implementation (initInstance). If the constructor or initialization throws, it is wrapped in IllegalStateException naming the ExtensionDefinition and service type, with the original throwable as cause. This distinguishes 'provider found but cannot be constructed' from 'provider not found'.","triggerScenarios":"Any EnhancedServiceLoader.load call where the selected provider class exists but initInstance fails: constructor exception, incompatible constructor signature when args are passed, abstract class registered as provider, or static initializer failure.","commonSituations":"Custom seata extensions with constructors requiring arguments while the loader calls the no-arg/argTypes path; providers depending on configuration that is not yet initialized at load time; JDK/security restrictions blocking reflective access.","solutions":["Read the cause (t) — its message and class identify the actual construction failure.","Give the provider a public constructor matching the argTypes passed to load(), typically a no-arg constructor.","Move provider initialization work out of the constructor into an init/lifecycle method.","Ensure the provider class is concrete and public."],"exampleFix":"// before\npublic class MyRegistryProvider implements RegistryProvider {\n  public MyRegistryProvider(String addr) { ... } // no no-arg ctor -> instantiation fails\n}\n\n// after\npublic class MyRegistryProvider implements RegistryProvider {\n  public MyRegistryProvider() { this.addr = System.getProperty(\"registry.addr\")); }\n}","handlingStrategy":"try-catch","validationCode":"// Optional pre-check that the provider class has a usable constructor\nClass<?> c = Class.forName(implName);\nif (!Modifier.isPublic(c.getModifiers()) || Modifier.isAbstract(c.getModifiers())) {\n    throw new IllegalArgumentException(\"SPI impl must be public and concrete: \" + implName);\n}\nif (Stream.of(c.getConstructors()).noneMatch(ctor -> ctor.getParameterCount() == 0)) {\n    throw new IllegalArgumentException(\"SPI impl needs a public no-arg constructor: \" + implName);\n}","typeGuard":null,"tryCatchPattern":"try {\n    T provider = EnhancedServiceLoader.load(SpiType.class);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"could not be instantiated\")) {\n        Throwable real = e.getCause(); // actual constructor/init failure\n        log.error(\"Provider init failed: {}\", real, real);\n    }\n    throw e;\n}","preventionTips":["Give every SPI implementation a public no-arg constructor.","Move external connections and heavy IO out of constructors into lazy init methods.","Cover custom providers with instantiation unit tests using the same loader path."],"tags":["spi","reflection","instantiation","provider","seata"],"backgroundTag":null,"analyzedSha":"e01f97c6db397165050caa6764020410c2c8199a","analyzedAt":"2026-08-14T10:23:53.097Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}