{"record":{"id":"8499acfde77333ef","repo":"OpenFeign/feign","slug":"at-least-one-encoder-is-required","errorCode":null,"errorMessage":"at least one encoder is required","messagePattern":"at least one encoder is required","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/codec/MultiEncoder.java","lineNumber":237,"sourceCode":"     *     .add(EncoderPredicate.any(), new DefaultEncoder())\n     *     .build();\n     * </pre>\n     *\n     * @param predicate narrows what the encoder handles\n     * @param encoder the encoder to delegate to\n     */\n    public Builder narrow(EncoderPredicate predicate, Encoder encoder) {\n      return add(PredicatedEncoder.narrowing(predicate, encoder));\n    }\n\n    /**\n     * Builds the multi-encoder.\n     *\n     * @throws IllegalStateException if no encoder was added\n     */\n    public MultiEncoder build() {\n      if (encoders.isEmpty()) {\n        throw new IllegalStateException(\"at least one encoder is required\");\n      }\n      return new MultiEncoder(encoders);\n    }\n  }\n}\n","sourceCodeStart":219,"sourceCodeEnd":243,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/codec/MultiEncoder.java#L219-L243","documentation":"The MultiEncoder.Builder requires at least one encoder; calling build() with none registered throws this IllegalStateException as a fail-fast guard. This prevents constructing an encoder that could never serialize any request body.","triggerScenarios":"Calling new MultiEncoder.Builder().build() (or code that builds it) without any add(...) call.","commonSituations":"Dynamic configuration where encoders are added conditionally (e.g. only when a JSON library is detected) and all conditions failed; refactoring removed the add calls; template builder code copied without the registration lines.","solutions":["Add at least one encoder before build(), e.g. .add(new Encoder.Default()) or .add(new JacksonEncoder())","Guard dynamic assembly: fall back to a default encoder when the candidate list is empty","Confirm the codec dependency providing the intended encoder is actually on the classpath"],"exampleFix":"// before\nEncoder e = new MultiEncoder.Builder().build();\n// after\nEncoder e = new MultiEncoder.Builder().add(new Encoder.Default()).build();","handlingStrategy":"validation","validationCode":"if (encoders.isEmpty()) {\n  encoders.add(new Encoder.Default());\n}\nMultiEncoder encoder = new MultiEncoder.Builder().add(encoders.toArray(new Encoder[0])).build();","typeGuard":null,"tryCatchPattern":"try {\n  this.encoder = multiEncoderBuilder.build();\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"at least one encoder\")) {\n    throw new ConfigurationException(\"No encoders registered for Feign client\", e);\n  }\n  throw e;\n}","preventionTips":["Guard dynamic encoder lists with a default fallback before build()","Add factory tests asserting the builder always has at least one encoder","Keep encoder registration centralized with decoder registration"],"tags":["feign","configuration","builder","empty-collection"],"backgroundTag":"missing-required-argument","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"}