{"record":{"id":"9b81b0b1b828fa08","repo":"apache/hadoop","slug":"0-1-exceeds-max-len-2","errorCode":null,"errorMessage":"[{0}] = [{1}] exceeds max len [{2}]","messagePattern":"\\[(.+?)\\] = \\[(.+?)\\] exceeds max len \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/util/Check.java","lineNumber":128,"sourceCode":"\n  private static final Pattern IDENTIFIER_PATTERN = Pattern.compile(\"^\" + IDENTIFIER_PATTERN_STR + \"$\");\n\n  /**\n   * Verifies a value is a valid identifier,\n   * <code>[a-zA-Z_][a-zA-Z0-9_\\-]*</code>, up to a maximum length.\n   *\n   * @param value string to check if it is a valid identifier.\n   * @param maxLen maximun length.\n   * @param name the name to use in the exception message.\n   *\n   * @return the value.\n   *\n   * @throws IllegalArgumentException if the string is not a valid identifier.\n   */\n  public static String validIdentifier(String value, int maxLen, String name) {\n    Check.notEmpty(value, name);\n    if (value.length() > maxLen) {\n      throw new IllegalArgumentException(\n        MessageFormat.format(\"[{0}] = [{1}] exceeds max len [{2}]\", name, value, maxLen));\n    }\n    if (!IDENTIFIER_PATTERN.matcher(value).find()) {\n      throw new IllegalArgumentException(\n        MessageFormat.format(\"[{0}] = [{1}] must be \\\"{2}\\\"\", name, value, IDENTIFIER_PATTERN_STR));\n    }\n    return value;\n  }\n\n  /**\n   * Verifies an integer is greater than zero.\n   *\n   * @param value integer value.\n   * @param name the name to use in the exception message.\n   *\n   * @return the value.\n   *\n   * @throws IllegalArgumentException if the integer is zero or less.","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/util/Check.java#L110-L146","documentation":"Thrown by the Hadoop httpfs library's precondition helper Check.validIdentifier(value, maxLen, name) (hadoop-hdfs-httpfs, org.apache.hadoop.lib.util.Check:127) when a string passes the null/empty check but is longer than the caller-declared maxLen. The helper validates identifier-shaped values against [a-zA-Z_][a-zA-Z0-9_-]* with a length cap, and the message reports the parameter name, the offending value, and the limit. It is a plain IllegalArgumentException, so it aborts whatever startup or construction path was validating the value.","triggerScenarios":"Any call Check.validIdentifier(v, maxLen, name) where v.length() > maxLen, e.g. validIdentifier(\"filesystem-server-01\", 10, \"name\") (18 chars vs cap 10). In practice this hits embedders of the org.apache.hadoop.lib server/webapp framework validating config-derived identifiers (service or instance names) against a small hardcoded cap.","commonSituations":"A config-supplied service/instance name grows past the limit after a rename; a fully-qualified hostname is passed where a short identifier was expected; a maxLen copied from another call site that validates a different, shorter field.","solutions":["Shorten the value to at most maxLen characters (rename the service/instance in the config).","If the longer value is legitimate, raise the maxLen argument at the call site so the contract matches reality.","Sanitize the input before validation: trim whitespace and drop verbose segments (prefixes, domains).","Add boundary unit tests: length == maxLen passes, maxLen + 1 throws."],"exampleFix":"// before\nString serviceName = conf.get(\"service.name\", \"filesystem-server-01\");\nCheck.validIdentifier(serviceName, 10, \"service.name\"); // throws: exceeds max len [10]\n\n// after\nString serviceName = conf.get(\"service.name\", \"fssvc01\");\nCheck.validIdentifier(serviceName, 10, \"service.name\"); // ok","handlingStrategy":"validation","validationCode":"String value = conf.get(\"service.name\");\nint maxLen = 10;\nif (value == null || value.isEmpty()) throw new ConfigurationException(\"service.name is required\");\nif (value.length() > maxLen) throw new ConfigurationException(\"service.name must be <= \" + maxLen + \" chars: \" + value);","typeGuard":"static boolean isValidIdentifier(String v, int maxLen) {\n  return v != null && !v.isEmpty() && v.length() <= maxLen\n      && v.matches(\"[a-zA-Z_][a-zA-Z0-9_-]*\");\n}","tryCatchPattern":"try {\n  Check.validIdentifier(value, maxLen, name);\n} catch (IllegalArgumentException ex) {\n  // config error: fail fast with the offending property name\n  throw new ConfigurationException(\"Invalid config value: \" + ex.getMessage(), ex);\n}","preventionTips":["Validate config-derived identifiers once at startup and fail fast with the property name in the message.","Keep identifier-style values short by convention; forbid dots and spaces upstream.","Boundary-test the limit: length == maxLen passes, maxLen + 1 throws."],"tags":["java","hadoop","httpfs","validation","string-length"],"backgroundTag":"max-length-exceeded","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}