{"record":{"id":"a02c6b5f7ffee10f","repo":"OpenFeign/feign","slug":"variable-map-is-required","errorCode":null,"errorMessage":"variable map is required.","messagePattern":"variable map is required\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/template/Template.java","lineNumber":100,"sourceCode":"      Charset charset,\n      List<TemplateChunk> chunks) {\n    this.templateChunks.addAll(chunks);\n    this.allowUnresolved = ExpansionOptions.ALLOW_UNRESOLVED == allowUnresolved;\n    this.encode = encode;\n    this.encodeSlash = encodeSlash;\n    this.charset = charset;\n    this.template = this.toString();\n  }\n\n  /**\n   * Expand the template.\n   *\n   * @param variables containing the values for expansion.\n   * @return a fully qualified URI with the variables expanded.\n   */\n  public String expand(Map<String, ?> variables) {\n    if (variables == null) {\n      throw new IllegalArgumentException(\"variable map is required.\");\n    }\n\n    /* resolve all expressions within the template */\n    StringBuilder resolved = null;\n    for (TemplateChunk chunk : this.templateChunks) {\n      String expanded;\n      if (chunk instanceof Expression) {\n        expanded = this.resolveExpression((Expression) chunk, variables);\n      } else {\n        /* chunk is a literal value */\n        expanded = chunk.getValue();\n      }\n      if (expanded == null) {\n        continue;\n      }\n\n      /* append it to the result */\n      if (resolved == null) {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/template/Template.java#L82-L118","documentation":"Template.expand() requires a non-null variables map to perform URI template expansion. The library throws IllegalArgumentException immediately when null is passed because expansion without a variable map is undefined; callers should pass an empty map if there are no variables.","triggerScenarios":"Calling Template.expand(null) directly, or indirectly through RequestTemplates.expand when a null variable map reaches the template engine.","commonSituations":"Custom Target/RequestInterceptor code building templates manually; refactors where a variables map becomes null because an upstream lookup returned null; unit tests exercising expand with null.","solutions":["Pass an empty map (Collections.emptyMap()) instead of null when there are no variables","Null-check or default the variables map before calling expand","Find the upstream code producing null (e.g. a failed parameter lookup) and fix it"],"exampleFix":"// before\ntemplate.expand(null);\n// after\ntemplate.expand(Collections.emptyMap());","handlingStrategy":"validation","validationCode":"if (variables == null) {\n  variables = Collections.emptyMap();\n}\nString uri = template.expand(variables);","typeGuard":"boolean safeToExpand(Map<String, ?> vars) { return vars != null; }","tryCatchPattern":"try {\n  template.expand(vars);\n} catch (IllegalArgumentException e) {\n  // fall back to empty map or log config error\n}","preventionTips":["Default null maps to Collections.emptyMap() before template expansion","Null-check variables in interceptors/targets that build requests"],"tags":["uri-template","null-argument","validation"],"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"}