{"record":{"id":"96c37c9d539930cc","repo":"apache/hadoop","slug":"uri-is-not-in-the-expected-format","errorCode":null,"errorMessage":"URI: {} is not in the expected format","messagePattern":"URI: (.+?) is not in the expected format","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/StorageLocation.java","lineNumber":92,"sourceCode":"  private StorageLocation(StorageType storageType, URI uri) {\n    this.storageType = storageType;\n    if (uri.getScheme() == null || uri.getScheme().equals(\"file\")) {\n      // make sure all URIs that point to a file have the same scheme\n      uri = normalizeFileURI(uri);\n    }\n    baseURI = uri;\n  }\n\n  public static URI normalizeFileURI(URI uri) {\n    try {\n      File uriFile = new File(uri.getPath());\n      String uriStr = uriFile.toURI().normalize().toString();\n      if (uriStr.endsWith(\"/\")) {\n        uriStr = uriStr.substring(0, uriStr.length() - 1);\n      }\n      return new URI(uriStr);\n    } catch (URISyntaxException e) {\n      throw new IllegalArgumentException(\n              \"URI: \" + uri + \" is not in the expected format\");\n    }\n  }\n\n  public StorageType getStorageType() {\n    return this.storageType;\n  }\n\n  public URI getUri() {\n    return baseURI;\n  }\n\n  public URI getNormalizedUri() {\n    return baseURI.normalize();\n  }\n\n  public boolean matchesStorageDirectory(StorageDirectory sd)\n      throws IOException {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/StorageLocation.java#L74-L110","documentation":"StorageLocation.normalizeFileURI() converts a file-scheme URI through File.toURI(), strips a trailing slash, and re-parses it with new URI(...); a URISyntaxException there is wrapped in IllegalArgumentException('URI: ... is not in the expected format'). It is invoked from the StorageLocation constructor whenever the URI has no scheme or the 'file' scheme, i.e., for every local storage dir in dfs.datanode.data.dir.","triggerScenarios":"StorageLocation.parse()/new StorageLocation(type, uri) with a local path whose normalized file-URI string cannot be parsed by java.net.URI - in practice rare, since File.toURI() percent-encodes; reachable with unusual control characters or broken URI encodings produced by upstream code rather than plain paths.","commonSituations":"Malformed dfs.datanode.data.dir entries (unencoded special characters, stray quotes/backslashes from shell heredocs or config templating); programmatic construction of StorageLocation from a URI built with bad encoding; JVM differences in URI strictness after upgrades.","solutions":["Use plain absolute filesystem paths (or [DISK]/path) in dfs.datanode.data.dir - let Path/File do the encoding","If building URIs programmatically, construct them via new Path(location).toUri() instead of string concatenation","Sanitize the offending entry the message prints and restart the DataNode"],"exampleFix":"# before (hdfs-site.xml - bad encoding)\n<name>dfs.datanode.data.dir</name><value>/data/1, /data/2#bad\u0000</value>\n\n# after\n<name>dfs.datanode.data.dir</name><value>/data/1,/data/2</value>","handlingStrategy":"validation","validationCode":"import java.io.File;\nimport java.net.URI;\nURI safeNormalize(URI u) {\n  try {\n    String s = new File(u.getPath()).toURI().normalize().toString();\n    if (s.endsWith(\"/\")) s = s.substring(0, s.length() - 1);\n    return new URI(s);\n  } catch (java.net.URISyntaxException e) {\n    throw new IllegalArgumentException(\"Unparseable storage URI: \" + u, e);\n  }\n}\n// pre-check config entries before passing them to StorageLocation.parse","typeGuard":null,"tryCatchPattern":"try { StorageLocation.parse(entry); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"not in the expected format\")) { /* reject config entry with clear operator message */ } else throw e; }","preventionTips":["Use plain absolute paths in dfs.datanode.data.dir; avoid hand-built URI strings","Lint storage dirs for control characters/quotes during config deployment"],"tags":["hdfs","datanode","storage","uri","config","illegal-argument"],"backgroundTag":"uri-parse-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}