{"record":{"id":"fbc4f179a3f8ebec","repo":"apache/hadoop","slug":"network-locationpath-doesn-t-start-with","errorCode":null,"errorMessage":"Network Locationpath doesn't start with /: {}","messagePattern":"Network Locationpath doesn't start with /: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java","lineNumber":860,"sourceCode":"      }\n    }\n    return weight;\n  }\n\n  /** Normalize a path by stripping off any trailing {@link #PATH_SEPARATOR}.\n   * @param path path to normalize.\n   * @return the normalised path\n   * If <i>path</i>is null or empty {@link #ROOT} is returned\n   * @throws IllegalArgumentException if the first character of a non empty path\n   * is not {@link #PATH_SEPARATOR}\n   */\n  private static String normalizeNetworkLocationPath(String path) {\n    if (path == null || path.length() == 0) {\n      return ROOT;\n    }\n\n    if (path.charAt(0) != PATH_SEPARATOR) {\n      throw new IllegalArgumentException(\"Network Location\"\n          + \"path doesn't start with \" +PATH_SEPARATOR+ \": \"+path);\n    }\n\n    int len = path.length();\n    if (path.charAt(len-1) == PATH_SEPARATOR) {\n      return path.substring(0, len-1);\n    }\n    return path;\n  }\n\n  /**\n   * Sort nodes array by network distance to <i>reader</i>.\n   * <p>\n   * In a three-level topology, a node can be either local, on the same rack,\n   * or on a different rack from the reader. Sorting the nodes based on network\n   * distance from the reader reduces network traffic and improves\n   * performance.\n   * <p>","sourceCodeStart":842,"sourceCodeEnd":878,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java#L842-L878","documentation":"NetworkTopology.normalizeNetworkLocationPath validates location strings used inside the topology: null or empty maps to ROOT, but any non-empty path must start with '/' (PATH_SEPARATOR), otherwise IllegalArgumentException. It also strips one trailing '/'.","triggerScenarios":"Any internal path-normalization call where the location string is like \"default-rack\" or \"rack1/nodegroup\" — missing the leading slash. Reached via NetworkTopology's network-location handling (e.g. setNetworkLocation paths used by add/getDatanodesInRack).","commonSituations":"Topology scripts emitting bare rack names without a leading '/'; hand-built Node objects in tests with unnormalized locations; config values copied without the leading slash.","solutions":["Prefix every location with '/' — '/default-rack', '/dc1/rack1'","Normalize external input with NodeBase.normalize() before handing it to NetworkTopology","Fix the topology script to print absolute slash-prefixed paths"],"exampleFix":"// before\nnode.setNetworkLocation(\"default-rack\");\n\n// after\nnode.setNetworkLocation(\"/default-rack\");","handlingStrategy":"validation","validationCode":"String loc = node.getNetworkLocation();\nif (loc == null || loc.isEmpty()) loc = \"/default-rack\";\nelse if (loc.charAt(0) != '/') loc = \"/\" + loc;\nnode.setNetworkLocation(loc);","typeGuard":"static boolean isValidLocationPath(String loc) {\n  return loc == null || loc.isEmpty() || loc.charAt(0) == '/';\n}","tryCatchPattern":null,"preventionTips":["Centralize location formatting in one helper that always prefixes '/'","Validate topology script output format in tests before rollout"],"tags":["hadoop-common","network-topology","path-validation","java"],"backgroundTag":"network-location-path-format","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}