{"record":{"id":"fa0ce0fdceb262c3","repo":"OpenFeign/feign","slug":"unable-to-enrich-target","errorCode":null,"errorMessage":"Unable to enrich ${target}","messagePattern":"Unable to enrich (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/Capability.java","lineNumber":70,"sourceCode":"        .reduce(\n            componentToEnrich,\n            (target, capability) -> invoke(target, capability, capabilityToEnrich),\n            (component, enrichedComponent) -> enrichedComponent);\n  }\n\n  static Object invoke(Object target, Capability capability, Class<?> capabilityToEnrich) {\n    return Arrays.stream(capability.getClass().getMethods())\n        .filter(method -> method.getName().equals(\"enrich\"))\n        .filter(method -> method.getReturnType().isAssignableFrom(capabilityToEnrich))\n        .findFirst()\n        .map(\n            method -> {\n              try {\n                return method.invoke(capability, target);\n              } catch (IllegalAccessException\n                  | IllegalArgumentException\n                  | InvocationTargetException e) {\n                throw new RuntimeException(\"Unable to enrich \" + target, e);\n              }\n            })\n        .orElse(target);\n  }\n\n  default Client enrich(Client client) {\n    return client;\n  }\n\n  default AsyncClient<Object> enrich(AsyncClient<Object> client) {\n    return client;\n  }\n\n  default Retryer enrich(Retryer retryer) {\n    return retryer;\n  }\n\n  default RequestInterceptor enrich(RequestInterceptor requestInterceptor) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/Capability.java#L52-L88","documentation":"Thrown by Capability.invoke when reflectively invoking a Capability's enrich method on the target object throws IllegalAccessException, IllegalArgumentException, or InvocationTargetException. The user-provided Capability itself failed while enriching a component, so the builder aborts with the underlying cause attached.","triggerScenarios":"A Capability's enrich override throws at runtime (InvocationTargetException) — e.g. NPE inside the enrichment logic; or the method is invoked with a target of an unexpected type.","commonSituations":"Capability enrichment code that assumes non-null wrapped components or a specific client implementation; initialization code in a Capability that fails in a restricted environment (e.g. missing config, missing dependency).","solutions":["Read the cause of this RuntimeException — it is the real exception thrown inside your Capability's enrich method","Fix the enrich override to be null-safe and to return the original target when it cannot enrich (return target as fallback)","Wrap your enrichment logic in try/catch inside the Capability and degrade gracefully instead of throwing"],"exampleFix":"// before\n@Override\npublic Client enrich(Client client) {\n  return new TracingClient((MonitoringClient) client); // ClassCastException for other impls\n}\n// after\n@Override\npublic Client enrich(Client client) {\n  if (client instanceof MonitoringClient) {\n    return new TracingClient((MonitoringClient) client);\n  }\n  return client; // fallback: leave unenriched\n}","handlingStrategy":"try-catch","validationCode":"try {\n  Client enriched = capability.enrich(existingClient);\n} catch (Exception e) {\n  throw new IllegalStateException(\"Capability enrichment is not safe\", e);\n}","typeGuard":null,"tryCatchPattern":"try { Feign.builder().addCapability(cap).build(); }\ncatch (RuntimeException e) { if (e.getMessage().startsWith(\"Unable to enrich \")) { /* see e.getCause() */ } }","preventionTips":["Keep enrich overrides side-effect-free and null-safe","Return the original target when enrichment is not applicable","Initialize Capability state lazily and defensively (missing config should not throw)","Unit-test each Capability's enrich methods against multiple client/encoder implementations"],"tags":["java","feign","reflection","capability"],"backgroundTag":"invalid-argument-value","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"}