{"record":{"id":"b33836a033e76c48","repo":"OpenFeign/feign","slug":"template-is-required","errorCode":null,"errorMessage":"template is required.","messagePattern":"template is required\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/template/Template.java","lineNumber":59,"sourceCode":"  private final Charset charset;\n  private final List<TemplateChunk> templateChunks = new ArrayList<>();\n\n  /**\n   * Create a new Template.\n   *\n   * @param value of the template.\n   * @param allowUnresolved if unresolved expressions should remain.\n   * @param encode all values.\n   * @param encodeSlash if slash characters should be encoded.\n   */\n  Template(\n      String value,\n      ExpansionOptions allowUnresolved,\n      EncodingOptions encode,\n      boolean encodeSlash,\n      Charset charset) {\n    if (value == null) {\n      throw new IllegalArgumentException(\"template is required.\");\n    }\n    this.template = value;\n    this.allowUnresolved = ExpansionOptions.ALLOW_UNRESOLVED == allowUnresolved;\n    this.encode = encode;\n    this.encodeSlash = encodeSlash;\n    this.charset = charset;\n    this.parseTemplate();\n  }\n\n  /**\n   * Create a new Template from the provided {@link TemplateChunk}s.\n   *\n   * @param allowUnresolved if unresolved expressions should remain.\n   * @param encode all values\n   * @param encodeSlash if slash characters should be encoded.\n   * @param charset of the result.\n   * @param chunks for this template.\n   */","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/template/Template.java#L41-L77","documentation":"feign.template.Template is the base class for URI/header/body templates. Its constructor throws IllegalArgumentException('template is required.') when the template string value is null. A null template has no meaning — there is nothing to parse into literals and expressions — so construction fails immediately.","triggerScenarios":"Passing a null value to the Template constructor or to subclasses that forward it (UriTemplate, HeaderTemplate body, etc.), typically when a template string comes from a nullable source: annotation values obtained reflectively, config lookups, or RequestTemplate paths that resolved to null.","commonSituations":"Custom Contract implementations reading annotation values that are null; building Feign targets/URIs from configuration where a base URL or path key is missing; generic template-building utilities with unvalidated inputs.","solutions":["Validate the template string is non-null before constructing; supply a sensible default (e.g. \"/\") if the source can be absent.","Fix the upstream source of the template (missing annotation value, missing config key) so a real template string is provided.","Wrap Template creation in try-catch for IllegalArgumentException and convert it into a configuration error message naming the missing template."],"exampleFix":"// before\nTemplate template = new UriTemplate(path, false, false); // path may be null\n// after\nObjects.requireNonNull(path, \"template path must not be null\");\nTemplate template = new UriTemplate(path, false, false);","handlingStrategy":"validation","validationCode":"if (templateValue == null) {\n  throw new IllegalArgumentException(\"template value must not be null (check configuration)\");\n}","typeGuard":"static boolean isValidTemplate(String s) {\n  return s != null;\n}","tryCatchPattern":"try {\n  Template t = new UriTemplate(value, false, false);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Template value was null; check config/annotations\", e);\n}","preventionTips":["Load template strings from configuration with explicit required-key checks (fail at startup, not at request time).","Never pass reflectively-read annotation values straight into Template without a null check.","Provide default template strings ('/') for optional path/header templates."],"tags":["java","feign","null-argument","uri-template","request-template"],"backgroundTag":"null-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"}