{"record":{"id":"962099389e39f93f","repo":"apache/shenyu","slug":"extension-instance-name-name-class-clazz-could-not-be","errorCode":null,"errorMessage":"Extension instance(name: name, class: clazz)  could not be instantiated: message","messagePattern":"Extension instance\\(name: name, class: clazz\\)  could not be instantiated: message","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"shenyu-spi/src/main/java/org/apache/shenyu/spi/ExtensionLoader.java","lineNumber":202,"sourceCode":"                    }).collect(Collectors.toList());\n        }\n        List<T> joins = new ArrayList<>();\n        List<ClassEntity> classEntities = extensionClassesEntity.values().stream()\n                .sorted(CLASS_ENTITY_COMPARATOR).collect(Collectors.toList());\n        classEntities.forEach(v -> {\n            T join = this.getJoin(v.getName());\n            joins.add(join);\n        });\n        return joins;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private Object createExtension(final ClassEntity classEntity) {\n        Class<?> aClass = classEntity.getClazz();\n        try {\n            return aClass.newInstance();\n        } catch (InstantiationException | IllegalAccessException e) {\n            throw new IllegalStateException(\"Extension instance(name: \" + classEntity.getName() + \", class: \"\n                    + aClass + \")  could not be instantiated: \" + e.getMessage(), e);\n\n        }\n    }\n    \n    @SuppressWarnings(\"unchecked\")\n    private void createExtension(final String name, final Holder<Object> holder) {\n        ClassEntity classEntity = getExtensionClassesEntity().get(name);\n        if (Objects.isNull(classEntity)) {\n            throw new IllegalArgumentException(name + \" name is error\");\n        }\n        Class<?> aClass = classEntity.getClazz();\n        Object o = joinInstances.get(aClass);\n        if (Objects.isNull(o)) {\n            o = createExtension(classEntity);\n            if (classEntity.isSingleton()) {\n                joinInstances.putIfAbsent(aClass, o);\n                o = joinInstances.get(aClass);","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-spi/src/main/java/org/apache/shenyu/spi/ExtensionLoader.java#L184-L220","documentation":"createExtension instantiates the resolved implementation class via Class.newInstance(). This IllegalStateException wraps InstantiationException or IllegalAccessException when the class cannot be instantiated — typically because it has no accessible no-arg constructor, is abstract, or is an inner/non-static class.","triggerScenarios":"An @Join implementation registered in META-INF/shenyu/ that is abstract, has only parameterized constructors, is not public, or is a non-static inner class, is requested via getJoin.","commonSituations":"SPI implementations with constructor-injected dependencies (works with Spring but not ShenYu SPI); abstract base class accidentally registered; anonymous/local classes; constructors made non-public after a refactor.","solutions":["Give the implementation a public no-argument constructor","Make the class non-abstract and concrete","Move inner classes to static or top-level","Obtain dependencies inside the constructor or via setters after instantiation instead of via constructor params"],"exampleFix":"// before\npublic class RoundRobinLoadBalance {\n    public RoundRobinLoadBalance(int modulo) { ... }\n}\n// after\npublic class RoundRobinLoadBalance {\n    public RoundRobinLoadBalance() { this.modulo = 1; }\n}","handlingStrategy":"try-catch","validationCode":"try { clazz.getDeclaredConstructor(); } catch (NoSuchMethodException e) { throw new IllegalStateException(clazz + \" lacks no-arg constructor\"); }","typeGuard":null,"tryCatchPattern":"try { return loader.getJoin(name); } catch (IllegalStateException e) { log.error(\"Cannot instantiate extension {}: {}\", name, e.getCause(), e); throw e; }","preventionTips":["Give every @Join implementation a public no-arg constructor","Never register abstract or non-static inner classes","Avoid constructor-injected dependencies in SPI implementations"],"tags":["spi","reflection","instantiation"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}