{"record":{"id":"ba768b976164b759","repo":"apache/hadoop","slug":"cannot-get-relative-path-for-uri-s","errorCode":null,"errorMessage":"Cannot get relative path for URI:%s","messagePattern":"Cannot get relative path for URI:(.+?)","errorType":"exception","errorClass":"PathIOException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/CopyFromLocalOperation.java","lineNumber":360,"sourceCode":"    }\n\n    if (!overwrite) {\n      throw new PathExistsException(dest + \" already exists\");\n    }\n  }\n\n  /**\n   * Get the final path of a source file with regards to its destination.\n   *\n   * @param src - source path\n   * @return - the final path for the source file to be uploaded to\n   * @throws PathIOException - if a relative path can't be created\n   */\n  private Path getFinalPath(Path src) throws PathIOException {\n    URI currentSrcUri = src.toUri();\n    URI relativeSrcUri = source.toUri().relativize(currentSrcUri);\n    if (relativeSrcUri.equals(currentSrcUri)) {\n      throw new PathIOException(\"Cannot get relative path for URI:\"\n          + relativeSrcUri);\n    }\n\n    Optional<FileStatus> status = getDestStatus();\n    if (!relativeSrcUri.getPath().isEmpty()) {\n      return new Path(destination, relativeSrcUri.getPath());\n    } else if (status.isPresent() && status.get().isDirectory()) {\n      // file to dir\n      return new Path(destination, src.getName());\n    } else {\n      // file to file\n      return destination;\n    }\n  }\n\n  private Optional<FileStatus> getDestStatus() {\n    return Optional.ofNullable(destStatus);\n  }","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/CopyFromLocalOperation.java#L342-L378","documentation":"Error \"Cannot get relative path for URI:%s\" thrown in apache/hadoop.","triggerScenarios":"Thrown at hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/CopyFromLocalOperation.java:360 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the source URI is under the base directory being copied so a relative path can be computed."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}