{"record":{"id":"bd5cfe5900869681","repo":"OpenFeign/feign","slug":"a-value-is-required","errorCode":null,"errorMessage":"a value is required.","messagePattern":"a value is required\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/template/Literal.java","lineNumber":40,"sourceCode":"\n  /**\n   * Create a new Literal.\n   *\n   * @param value of the literal.\n   * @return the new Literal.\n   */\n  public static Literal create(String value) {\n    return new Literal(value);\n  }\n\n  /**\n   * Create a new Literal.\n   *\n   * @param value of the literal.\n   */\n  Literal(String value) {\n    if (value == null || value.isEmpty()) {\n      throw new IllegalArgumentException(\"a value is required.\");\n    }\n    this.value = value;\n  }\n\n  @Override\n  public String getValue() {\n    return this.value;\n  }\n}\n","sourceCodeStart":22,"sourceCodeEnd":50,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/template/Literal.java#L22-L50","documentation":"feign.template.Literal represents a fixed (non-variable) text segment inside a request template. Its package-private constructor rejects null or empty strings, since a Literal with no content is meaningless. IllegalArgumentException('a value is required.') is thrown at construction time.","triggerScenarios":"Constructing Literal directly (within the template package) with a null or \"\" value. Indirectly, via template parsing code that chunked a template into literal/variable segments and produced an empty literal chunk (e.g. adjacent variables like {a}{b}, or a template starting/ending with a variable in some code paths).","commonSituations":"Feign URI template strings with empty segments or adjacent placeholders; custom template parsing/extending code in the feign.template package; unit-testing template internals with empty strings.","solutions":["Ensure the string passed to the Literal constructor is non-null and non-empty; filter out empty chunks before constructing.","If parsing your own template, guard each segment: only create a Literal when segment.length() > 0.","Catch IllegalArgumentException around template construction to detect malformed template input and surface a clearer message to the user."],"exampleFix":"// before\nnew Literal(chunk); // chunk may be \"\"\n// after\nif (chunk != null && !chunk.isEmpty()) {\n  new Literal(chunk);\n}","handlingStrategy":"validation","validationCode":"if (value == null || value.isEmpty()) {\n  return; // skip empty literal segment\n}","typeGuard":"static boolean isNonEmptyLiteral(String s) {\n  return s != null && !s.isEmpty();\n}","tryCatchPattern":"try {\n  new Literal(segment);\n} catch (IllegalArgumentException e) {\n  // segment was null/empty; skip or log malformed template chunk\n}","preventionTips":["Filter template chunks for emptiness before wrapping them in Literal.","Validate template strings for stray empty segments (e.g. '{}') before parsing.","When testing template internals, always provide non-empty strings."],"tags":["java","feign","empty-string","uri-template","request-template"],"backgroundTag":"empty-required-field","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"}