{"record":{"id":"cbcfa44d096c7244","repo":"OpenFeign/feign","slug":"expression-is-too-long-max-length-maxexpression","errorCode":null,"errorMessage":"expression is too long. Max length: {maxExpressionLength}","messagePattern":"expression is too long\\. Max length: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/template/Expressions.java","lineNumber":92,"sourceCode":"          \"(([\\\\w-\\\\[\\\\]$]|%[0-9A-Fa-f]{2})(\\\\.?([\\\\w-\\\\[\\\\]$]|%[0-9A-Fa-f]{2}))*(:.*|\\\\*)?)(,(([\\\\w-\\\\[\\\\]$]|%[0-9A-Fa-f]{2})(\\\\.?([\\\\w-\\\\[\\\\]$]|%[0-9A-Fa-f]{2}))*(:.*|\\\\*)?))*\");\n\n  public static Expression create(final String value) {\n\n    /* remove the start and end braces */\n    final String expression = stripBraces(value);\n    if (expression == null || expression.isEmpty()) {\n      throw new IllegalArgumentException(\"an expression is required.\");\n    }\n\n    /*\n     * Check if the expression is too long. The limit is configurable through the\n     * \"feign.template.expression.maxLength\" system property and can be disabled by setting it to a\n     * non-positive value.\n     */\n    final int maxExpressionLength =\n        Integer.getInteger(MAX_EXPRESSION_LENGTH_PROPERTY, DEFAULT_MAX_EXPRESSION_LENGTH);\n    if (maxExpressionLength > 0 && expression.length() > maxExpressionLength) {\n      throw new IllegalArgumentException(\n          \"expression is too long. Max length: \" + maxExpressionLength);\n    }\n\n    /* create a new regular expression matcher for the expression */\n    String variableName = null;\n    String variablePattern = null;\n    String operator = null;\n    Matcher matcher = EXPRESSION_PATTERN.matcher(value);\n    if (matcher.matches()) {\n      /* grab the operator */\n      operator = matcher.group(2).trim();\n\n      /* we have a valid variable expression, extract the name from the first group */\n      variableName = matcher.group(3).trim();\n      if (variableName.contains(\":\")) {\n        /* split on the colon and ensure the size of parts array must be 2 */\n        String[] parts = variableName.split(\":\", 2);\n        variableName = parts[0];","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/template/Expressions.java#L74-L110","documentation":"Feign's template parser limits how long a single URI template expression ({...}) may be, for safety and to avoid pathological regex building. The limit defaults via the 'feign.template.expression.maxLength' system property and can be disabled by setting it to a non-positive value. When the expression text between braces exceeds that length, Expressions.create throws this IllegalArgumentException before compiling the expression.","triggerScenarios":"Calling RequestTemplate.append/insert or resolving a URI whose {...} expression is longer than the configured max (default 1000 chars); building templates programmatically with very large variable sub-patterns; passing user-supplied strings into template variables that themselves become expressions.","commonSituations":"Interpolating large JSON or base64 blobs into URL placeholders; misconfigured system property 'feign.template.expression.maxLength'; accidental double-template-processing where an already-expanded URL containing braces gets re-parsed as a template; dynamically generated query expressions from untrusted input.","solutions":["Shorten the expression: move large values out of the URI template and pass them via request body or headers instead.","Raise or disable the limit by setting system property -Dfeign.template.expression.maxLength=-1 (disable) or a larger positive value.","Check that you are not re-parsing already-expanded URLs; mark literals with RequestTemplate.literal or escape braces.","Sanitize/truncate user input before placing it into template variables."],"exampleFix":"// before\nRequestTemplate tpl = new RequestTemplate().append(\"/search?filter={filter}\");\ntpl.resolve(Collections.singletonMap(\"filter\", hugeJsonString)); // expression too long\n// after\nRequestTemplate tpl = new RequestTemplate().append(\"/search\");\ntpl.query(\"filter\", hugeJsonString); // plain value, not a template expression","handlingStrategy":"validation","validationCode":"int max = Math.max(Integer.getInteger(\"feign.template.expression.maxLength\", 1000), 0);\nif (expression != null && expression.length() > max) {\n  throw new IllegalArgumentException(\"expression exceeds \" + max + \" chars\");\n}","typeGuard":"static boolean safeExpression(String e) {\n  int max = Integer.getInteger(\"feign.template.expression.maxLength\", 1000);\n  return max <= 0 || (e != null && e.length() <= max);\n}","tryCatchPattern":"try {\n  template.resolve(variables);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"expression is too long\")) {\n    // fall back to body/POST or truncate value\n  } else throw e;\n}","preventionTips":["Keep large payloads out of URI expressions — use body or query values appended directly.","Never re-parse already-expanded URLs as templates.","Set feign.template.expression.maxLength deliberately in your environment and document it.","Truncate or reject oversized user input before template resolution."],"tags":["feign","uri-template","template-expression","limit-exceeded"],"backgroundTag":"value-out-of-range","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"}