Forráskód Böngészése

Normalise path to fix file uri in windows (#7756)

* This PR prefixes `/` to the path on Windows to
  address the `URISyntaxException`.
ASHISH-RANJAN59 1 hete
szülő
commit
252b797fd5

+ 8 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java

@@ -258,7 +258,14 @@ public class Path
   private void initialize(String scheme, String authority, String path,
       String fragment) {
     try {
-      this.uri = new URI(scheme, authority, normalizePath(scheme, path), null, fragment)
+      // Normalize the path
+      String normalizedPath = normalizePath(scheme, path);
+
+      // Windows-specific fix: file URIs must start with "/"
+      if ("file".equalsIgnoreCase(scheme) && normalizedPath.matches("^[A-Za-z]:.*")) {
+        normalizedPath = "/" + normalizedPath.replace("\\", "/");
+      }
+      this.uri = new URI(scheme, authority, normalizedPath, null, fragment)
         .normalize();
     } catch (URISyntaxException e) {
       throw new IllegalArgumentException(e);