Skip to content

Commit 252b797

Browse files
Normalise path to fix file uri in windows (#7756)
* This PR prefixes `/` to the path on Windows to address the `URISyntaxException`.
1 parent 1071795 commit 252b797

File tree

1 file changed

+8
-1
lines changed
  • hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,14 @@ public Path(String scheme, String authority, String path) {
258258
private void initialize(String scheme, String authority, String path,
259259
String fragment) {
260260
try {
261-
this.uri = new URI(scheme, authority, normalizePath(scheme, path), null, fragment)
261+
// Normalize the path
262+
String normalizedPath = normalizePath(scheme, path);
263+
264+
// Windows-specific fix: file URIs must start with "/"
265+
if ("file".equalsIgnoreCase(scheme) && normalizedPath.matches("^[A-Za-z]:.*")) {
266+
normalizedPath = "/" + normalizedPath.replace("\\", "/");
267+
}
268+
this.uri = new URI(scheme, authority, normalizedPath, null, fragment)
262269
.normalize();
263270
} catch (URISyntaxException e) {
264271
throw new IllegalArgumentException(e);

0 commit comments

Comments
 (0)