{"record":{"id":"abd4d73a8ab0e55a","repo":"apache/hadoop","slug":"value-is-not-in-expected-format-expected-format","errorCode":null,"errorMessage":"${value} is not in expected format.Expected format is <number><unit>. e.g. 1000MB","messagePattern":"(.+?) is not in expected format\\.Expected format is <number><unit>\\. e\\.g\\. 1000MB","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/StorageSize.java","lineNumber":64,"sourceCode":"      throw new IllegalStateException(errorString);\n    }\n  }\n\n  public static StorageSize parse(String value) {\n    checkState(isNotBlank(value), \"value cannot be blank\");\n    String sanitizedValue = value.trim().toLowerCase(Locale.ENGLISH);\n    StorageUnit parsedUnit = null;\n    for (StorageUnit unit : StorageUnit.values()) {\n      if (sanitizedValue.endsWith(unit.getShortName()) ||\n          sanitizedValue.endsWith(unit.getLongName()) ||\n          sanitizedValue.endsWith(unit.getSuffixChar())) {\n        parsedUnit = unit;\n        break;\n      }\n    }\n\n    if (parsedUnit == null) {\n      throw new IllegalArgumentException(value + \" is not in expected format.\" +\n          \"Expected format is <number><unit>. e.g. 1000MB\");\n    }\n\n\n    String suffix = \"\";\n    boolean found = false;\n\n    // We are trying to get the longest match first, so the order of\n    // matching is getLongName, getShortName and then getSuffixChar.\n    if (!found && sanitizedValue.endsWith(parsedUnit.getLongName())) {\n      found = true;\n      suffix = parsedUnit.getLongName();\n    }\n\n    if (!found && sanitizedValue.endsWith(parsedUnit.getShortName())) {\n      found = true;\n      suffix = parsedUnit.getShortName();\n    }","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/StorageSize.java#L46-L82","documentation":"After the blank check, StorageSize.parse() trims and lowercases the input, then scans StorageUnit values (EB..B, checked longest-short-name first) for a trailing unit via long name, short name, or suffix char. If none matches, it throws IllegalArgumentException demanding the <number><unit> form, e.g. \"1000MB\". The remaining numeric prefix is later consumed by Double.parseDouble.","triggerScenarios":"parse(\"4096\") with no unit; parse(\"1000MiB\") (IEC unit not a StorageUnit name); parse(\"foo\"); parse(\"1tb2\") — any string that does not end in a StorageUnit short name (b/kb/mb/gb/tb/pb/eb), long name (bytes/kilobytes/.../exabytes), or suffix char.","commonSituations":"Bare-number size values migrated from older configs or other tools that accepted unitless numbers; values copied from Linux docs using MiB/GiB; unit typos; trailing garbage after the unit.","solutions":["Append a supported unit, e.g. change 4096 to 4096MB","Check the StorageUnit enum for accepted long names, short names, and suffix chars and correct the value to one of them","When migrating legacy bare numbers, convert them programmatically to <number><unit> strings before parse"],"exampleFix":"<!-- before -->\n<property><name>some.size.key</name><value>4096</value></property>\n\n<!-- after -->\n<property><name>some.size.key</name><value>4096MB</value></property>","handlingStrategy":"validation","validationCode":"private static final Pattern SIZE = Pattern.compile(\n    \"^[0-9]+(\\\\.[0-9]+)?(b|kb|mb|gb|tb|pb|eb|bytes|kilobytes|megabytes|gigabytes|terabytes|petabytes|exabytes)$\");\n\nString v = raw.trim().toLowerCase(Locale.ENGLISH);\nif (!SIZE.matcher(v).matches()) {\n  throw new IllegalArgumentException(raw + \" must be <number><unit>, e.g. 1000MB\");\n}\nreturn StorageSize.parse(raw);","typeGuard":null,"tryCatchPattern":"try {\n  size = StorageSize.parse(raw);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(key + \" has invalid value '\" + raw + \"'; expected <number><unit> like 1000MB\", e);\n}","preventionTips":["Validate size strings at config load time with a <number><unit> regex","Reject IEC units (MiB/GiB) early — only decimal StorageUnit names are accepted","Document one canonical unit per key and enforce it in config templates"],"tags":["configuration","validation","parsing","storage","hadoop"],"backgroundTag":"invalid-config-format","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}