{"record":{"id":"fdd00c6e4862d8fe","repo":"OpenFeign/feign","slug":"unable-to-enrich-field-field","errorCode":null,"errorMessage":"Unable to enrich field ${field}","messagePattern":"Unable to enrich field (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/BaseBuilder.java","lineNumber":364,"sourceCode":"                  final Object originalValue = field.get(clone);\n                  final Object enriched;\n                  if (originalValue instanceof List) {\n                    Type ownerType =\n                        ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];\n                    enriched =\n                        ((List) originalValue)\n                            .stream()\n                                .map(\n                                    value ->\n                                        Capability.enrich(\n                                            value, (Class<?>) ownerType, capabilities))\n                                .collect(Collectors.toList());\n                  } else {\n                    enriched = Capability.enrich(originalValue, field.getType(), capabilities);\n                  }\n                  field.set(clone, enriched);\n                } catch (IllegalArgumentException | IllegalAccessException e) {\n                  throw new RuntimeException(\"Unable to enrich field \" + field, e);\n                } finally {\n                  field.setAccessible(false);\n                }\n              });\n\n      // enrich each request interceptor, then enrich the list as a whole\n      RequestInterceptor[] requestArray =\n          clone.requestInterceptors.toArray(new RequestInterceptor[0]);\n      for (int i = 0; i < requestArray.length; i++) {\n        requestArray[i] =\n            (RequestInterceptor)\n                Capability.enrich(requestArray[i], RequestInterceptor.class, capabilities);\n      }\n      RequestInterceptors requestInterceptors =\n          (RequestInterceptors)\n              Capability.enrich(\n                  new RequestInterceptors(Arrays.asList(requestArray)),\n                  RequestInterceptors.class,","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/BaseBuilder.java#L346-L382","documentation":"Thrown by BaseBuilder.enrich when applying Capabilities to a builder field fails via reflection: field.set(clone, enriched) throws IllegalArgumentException (value not assignable to the field type) or IllegalAccessException. This wraps the reflective enrichment of builder components (clients, encoders, decoders, interceptors) with a Capability-enriched replacement.","triggerScenarios":"A Capability.enrich returns an object whose type does not implement the field's declared interface type (e.g. a Capability returning a wrong-typed wrapper); or a builder field is not accessible in this environment.","commonSituations":"Custom Capability whose enrich override returns an incompatible instance due to generics erasure or a wrong cast; upgrading Feign and a Capability targeting a field type that changed.","solutions":["Fix the Capability so enrich returns an instance assignable to the component's interface type (Client, Encoder, Decoder, etc.)","Log/inspect the cause IllegalArgumentException message which names the offending field and expected type","Disable the suspect Capability and re-enable components one by one to find which one returns the wrong type"],"exampleFix":"// before\nclass BadCapability implements Capability {\n  @Override\n  public Encoder enrich(Encoder encoder) { return null; } // null/wrong type\n}\n// after\nclass GoodCapability implements Capability {\n  @Override\n  public Encoder enrich(Encoder encoder) {\n    return new MyEncoderWrapper(encoder); // must implement feign Encoder\n  }\n}","handlingStrategy":"validation","validationCode":"Object out = capability.enrich(original);\nif (out != null && !fieldType.isInstance(out)) {\n  throw new IllegalStateException(fieldType.getName() + \" required, got \" + out.getClass());\n}","typeGuard":"boolean validEnrichment(Object out, Class<?> fieldType) {\n  return out == null || fieldType.isInstance(out);\n}","tryCatchPattern":"try { Feign.builder().addCapability(cap).build(); }\ncatch (RuntimeException e) { if (e.getMessage().startsWith(\"Unable to enrich field\")) { /* wrong-type Capability */ } }","preventionTips":["Capability enrich methods must return instances assignable to the component interface","Never return null from enrich — return the original component instead","Test each Capability in isolation with Feign.builder().addCapability(...).build()"],"tags":["java","feign","reflection","capability"],"backgroundTag":"type-mismatch","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}