{"record":{"id":"76836581135707c7","repo":"alibaba/spring-cloud-alibaba","slug":"feignclientfactory-not-initialized","errorCode":null,"errorMessage":"FeignClientFactory not initialized","messagePattern":"FeignClientFactory not initialized","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java","lineNumber":147,"sourceCode":"\t\t\t\t\t\treturn new SentinelInvocationHandler(target, dispatch,\n\t\t\t\t\t\t\t\tnew FallbackFactory.Default(fallbackInstance));\n\t\t\t\t\t}\n\t\t\t\t\tif (void.class != fallbackFactory) {\n\t\t\t\t\t\tfallbackFactoryInstance = (FallbackFactory) getFromContext(\n\t\t\t\t\t\t\t\tbeanName, \"fallbackFactory\", fallbackFactory,\n\t\t\t\t\t\t\t\tFallbackFactory.class);\n\t\t\t\t\t\treturn new SentinelInvocationHandler(target, dispatch,\n\t\t\t\t\t\t\t\tfallbackFactoryInstance);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn new SentinelInvocationHandler(target, dispatch);\n\t\t\t\t}\n\n\t\t\t\tprivate Object getFromContext(String name, String type,\n\t\t\t\t\t\tClass fallbackType, Class targetType) {\n\t\t\t\t\tFeignClientFactory factory = Builder.this.feignClientFactory;\n\t\t\t\t\tif (factory == null) {\n\t\t\t\t\t\tthrow new IllegalStateException(\"FeignClientFactory not initialized\");\n\t\t\t\t\t}\n\t\t\t\t\tObject fallbackInstance = factory.getInstance(name,\n\t\t\t\t\t\t\tfallbackType);\n\t\t\t\t\tif (fallbackInstance == null) {\n\t\t\t\t\t\tthrow new IllegalStateException(String.format(\n\t\t\t\t\t\t\t\t\"No %s instance of type %s found for feign client %s\",\n\t\t\t\t\t\t\t\ttype, fallbackType, name));\n\t\t\t\t\t}\n\t\t\t\t\t// when fallback is a FactoryBean, should determine the type of instance\n\t\t\t\t\tif (fallbackInstance instanceof FactoryBean<?> factoryBean) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tfallbackInstance = factoryBean.getObject();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (Exception e) {\n\t\t\t\t\t\t\tthrow new IllegalStateException(type + \" create fail\", e);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (fallbackInstance == null) {\n\t\t\t\t\t\t\tthrow new IllegalStateException(type + \" FactoryBean returned null\");","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/feign/SentinelFeign.java#L129-L165","documentation":"The private helper getFromContext, used to resolve fallback or fallbackFactory instances from the FeignClientFactory child context, begins by asserting the factory is non-null. This is a defensive re-check in a code path that should already have been guarded by error 111; if reached with a null factory it means the builder lost its reference mid-resolution.","triggerScenarios":"Same root causes as error 111 but encountered after the initial build, during per-client fallback resolution when the builder's feignClientFactory field is null. Theoretically reachable via custom SentinelFeign subclassing that clears the factory.","commonSituations":"Custom Feign builder that nulls out the factory. Race during reconfiguration. Version skew in the Sentinel feign integration.","solutions":["Apply the same fixes as error 111: ensure the SentinelFeign builder carries a non-null FeignClientFactory.","Do not subclass/replace SentinelFeign.Builder in a way that drops the factory field.","Confirm feign + sentinel starters versions are compatible."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"void buildWithFactory(SentinelFeign.Builder b) {\n  if (b.getFeignClientFactory() == null) throw new IllegalStateException(\"feignClientFactory must be set before build\");\n  b.build();\n}","typeGuard":null,"tryCatchPattern":"try { resolveFallback(factory, type); }\ncatch (IllegalStateException e) { if (factory == null) { factory = refreshFactory(); /* retry once */ } else throw e; }","preventionTips":["Do not null out the builder's feignClientFactory.","Keep feign and sentinel starter versions compatible.","Avoid subclassing SentinelFeign.Builder destructively."],"tags":["sentinel","feign","fallback","defensive-check"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}