{"record":{"id":"b3d48575983af2dc","repo":"OpenFeign/feign","slug":"e-getmessage-b3d485","errorCode":null,"errorMessage":"${e.getMessage()}","messagePattern":"\\$\\{e\\.getMessage\\(\\)\\}","errorType":"exception","errorClass":"EncodeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/RequestTemplateFactoryResolver.java","lineNumber":239,"sourceCode":"      super(metadata, queryMapEncoder, target);\n      this.encoder = encoder;\n    }\n\n    @Override\n    protected RequestTemplate resolve(\n        Object[] argv, RequestTemplate mutable, Map<String, Object> variables) {\n      Map<String, Object> formVariables = new LinkedHashMap<String, Object>();\n      for (Map.Entry<String, Object> entry : variables.entrySet()) {\n        if (metadata.formParams().contains(entry.getKey())) {\n          formVariables.put(entry.getKey(), entry.getValue());\n        }\n      }\n      try {\n        encoder.encode(formVariables, Encoder.MAP_STRING_WILDCARD, mutable);\n      } catch (EncodeException e) {\n        throw e;\n      } catch (RuntimeException e) {\n        throw new EncodeException(e.getMessage(), e);\n      }\n      return super.resolve(argv, mutable, variables);\n    }\n  }\n\n  static class BuildEncodedTemplateFromArgs extends BuildTemplateByResolvingArgs {\n\n    private final Encoder encoder;\n\n    BuildEncodedTemplateFromArgs(\n        MethodMetadata metadata, Encoder encoder, QueryMapEncoder queryMapEncoder, Target target) {\n      super(metadata, queryMapEncoder, target);\n      this.encoder = encoder;\n    }\n\n    @Override\n    protected RequestTemplate resolve(\n        Object[] argv, RequestTemplate mutable, Map<String, Object> variables) {","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/RequestTemplateFactoryResolver.java#L221-L257","documentation":"This wraps any unexpected RuntimeException thrown while encoding form variables into an EncodeException, preserving the original message and cause. Feign does this so callers can catch a single codec exception type when template resolution fails. It is a pass-through wrapper, not a distinct failure mode.","triggerScenarios":"A @Form/@Body form-encoding request is resolved via RequestTemplateFactoryResolver$FormFieldResolver.resolve and the configured Encoder throws a RuntimeException (e.g. NPE inside Jackson/Gson encoder) while encoding the form variables map.","commonSituations":"A custom Encoder throws unchecked exceptions; a JSON encoder is misconfigured (no ObjectMapper set) or receives an unencodable object; null field values in form data trip encoder internals.","solutions":["Read the wrapped cause (e.getCause()) to find the real encoder failure","Fix the underlying encoder bug or configuration revealed by the cause","Register a proper Encoder (e.g. Jackson/Gson) that handles the form map types","Add unit tests around the Encoder with the actual payload"],"exampleFix":"// before\nFeign.builder().encoder(new JacksonEncoder()) // no ObjectMapper configured -> NPE wrapped as EncodeException\n// after\nFeign.builder().encoder(new JacksonEncoder(new ObjectMapper()))","handlingStrategy":"try-catch","validationCode":"// verify encoder handles the form map\nif (!(encoder instanceof feign.codec.Encoder)) throw new IllegalStateException(\"encoder required\");","typeGuard":"if (encoder == null) { /* configure before building client */ }","tryCatchPattern":"try { api.submit(form); } catch (EncodeException e) { log.error(\"encode failed: {}\", e.getMessage(), e.getCause()); throw new ClientConfigException(e); }","preventionTips":["Always configure a concrete encoder on Feign.builder()","Log the cause chain, not just the message","Unit-test encoders with real payloads","Keep encoder configuration (ObjectMapper etc.) centralized"],"tags":["encoding","encoder","runtime-exception-wrapped","java"],"backgroundTag":"json-marshal-failed","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"}