From ac5db4f1d21724103b447be1350093edfe420aea Mon Sep 17 00:00:00 2001 From: ranjanash Date: Sat, 21 Jun 2025 21:59:06 +0530 Subject: [PATCH] Normalise path to fix file uri in windows --- .../src/main/java/org/apache/hadoop/fs/Path.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java index f4dec29a640b4..bcbdd0c193258 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java @@ -258,7 +258,14 @@ public Path(String scheme, String authority, String 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);