Skip to content

HADOOP-19815. Document Path URI vs String constructor and trailing sl…#8307

Open
deepujain wants to merge 6 commits intoapache:trunkfrom
deepujain:HADOOP-19815-path-uri-trailing-slash-docs
Open

HADOOP-19815. Document Path URI vs String constructor and trailing sl…#8307
deepujain wants to merge 6 commits intoapache:trunkfrom
deepujain:HADOOP-19815-path-uri-trailing-slash-docs

Conversation

@deepujain
Copy link
Contributor

@deepujain deepujain commented Mar 7, 2026

Summary

Documents how Path handles trailing slashes and how that affects URI.resolve(), and fixes the FileSystem side of the issue. The String constructor (and other constructors that use string path components) normalize the path and remove trailing slashes; the URI constructor preserves the provided URI after URI.normalize(), including any trailing slash. In addition, FileSystem now returns directory-form URIs/Paths: getUri(), getWorkingDirectory(), and getHomeDirectory() have a trailing slash where appropriate, so fs.getWorkingDirectory().toUri().resolve("mytempdir") correctly yields .../user/me/mytempdir (per HADOOP-19815 and reviewer feedback).

Change

  • Path.java
    • Class-level Javadoc: "Trailing slash and URI resolution" (Path(URI) vs Path(String), impact on toUri().resolve()).
    • Path(String): noted that trailing slashes are removed; use Path(URI) when resolution must preserve a trailing slash.
    • Path(URI): noted that the URI is preserved including trailing slash.
    • New: Path.ensureDirectoryUri(URI) and Path.asDirectory() for directory-form URIs/Paths.
  • FileSystem.java
    • Javadoc for getUri(), getHomeDirectory(), getWorkingDirectory(): they return directory form (trailing slash). Default getHomeDirectory() returns ...asDirectory().
  • RawLocalFileSystem, DistributedFileSystem, ViewFileSystem, ChRootedFs, ChRootedFileSystem
    • getUri() uses Path.ensureDirectoryUri(...); getWorkingDirectory() / getHomeDirectory() return directory form (e.g. .asDirectory()).
  • Tests
    • TestPath: testTrailingSlashAndUriResolve (Path String vs URI), testEnsureDirectoryUri, testAsDirectoryAndResolve.
    • TestLocalFileSystem: testFileSystemDirectoryUriForResolve.
    • ViewFS/ChRooted tests updated for directory-form URIs/Paths.

JIRA

Fixes HADOOP-19815

…ash.

Clarify that Path(URI) preserves the URI including trailing slash while
Path(String) normalizes and strips trailing slashes; document impact on
URI.resolve() and when to use Path(URI) or path concatenation.
@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 53s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 1s codespell was not available.
+0 🆗 detsecrets 0m 1s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
-1 ❌ test4tests 0m 0s The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 50m 25s trunk passed
+1 💚 compile 19m 48s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 18m 18s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 1m 27s trunk passed
+1 💚 mvnsite 1m 59s trunk passed
+1 💚 javadoc 1m 29s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 25s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 3m 35s trunk passed
+1 💚 shadedclient 36m 53s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 35s the patch passed
+1 💚 compile 17m 10s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 17m 10s the patch passed
+1 💚 compile 18m 0s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 18m 0s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 25s hadoop-common-project/hadoop-common: The patch generated 0 new + 19 unchanged - 1 fixed = 19 total (was 20)
+1 💚 mvnsite 1m 57s the patch passed
+1 💚 javadoc 1m 22s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 20s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 3m 22s the patch passed
+1 💚 shadedclient 36m 38s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 22m 38s hadoop-common in the patch passed.
+1 💚 asflicense 1m 11s The patch does not generate ASF License warnings.
243m 50s
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8307/1/artifact/out/Dockerfile
GITHUB PR #8307
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 8807479cfef8 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 8d20f8e
Default Java Ubuntu-17.0.18+8-Ubuntu-124.04.1
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8307/1/testReport/
Max. process+thread count 1285 (vs. ulimit of 5500)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8307/1/console
versions git=2.43.0 maven=3.9.11 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 55s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 1s codespell was not available.
+0 🆗 detsecrets 0m 1s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
-1 ❌ test4tests 0m 0s The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 49m 29s trunk passed
+1 💚 compile 18m 48s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 18m 23s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 1m 26s trunk passed
+1 💚 mvnsite 2m 7s trunk passed
+1 💚 javadoc 1m 23s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 21s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 3m 18s trunk passed
+1 💚 shadedclient 37m 34s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 19s the patch passed
+1 💚 compile 17m 56s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 17m 56s the patch passed
+1 💚 compile 18m 1s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 18m 1s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 26s hadoop-common-project/hadoop-common: The patch generated 0 new + 19 unchanged - 1 fixed = 19 total (was 20)
+1 💚 mvnsite 1m 55s the patch passed
+1 💚 javadoc 1m 20s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 22s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 3m 23s the patch passed
+1 💚 shadedclient 36m 8s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 22m 45s hadoop-common in the patch passed.
+1 💚 asflicense 1m 13s The patch does not generate ASF License warnings.
242m 48s
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8307/2/artifact/out/Dockerfile
GITHUB PR #8307
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 94e146a997d9 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 3ebbf91
Default Java Ubuntu-17.0.18+8-Ubuntu-124.04.1
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8307/2/testReport/
Max. process+thread count 1316 (vs. ulimit of 5500)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8307/2/console
versions git=2.43.0 maven=3.9.11 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@deepujain
Copy link
Contributor Author

My JIRA id is deepujain

Copy link
Member

@ctubbsii ctubbsii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to the changes to the docs, and the addition of the test. However, it does not fully resolve the issue described in the JIRA issue. To fully resolve the issue, the FileSystem methods need to be fixed, because their trailing slashes do matter.

@github-actions github-actions bot added the HDFS label Mar 9, 2026
@deepujain
Copy link
Contributor Author

@ctubbsii thanks for the review. I have made additional changes. Please take another look when you have a moment.

Copy link
Member

@ctubbsii ctubbsii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an improvement, but I had a question about how API changes should be marked in my below comments.

* @param uri a filesystem or path URI
* @return a URI with path ending in "/" (or "/" when path is empty)
*/
public static URI ensureDirectoryUri(URI uri) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need any API annotations? It seems to be a new public method in an otherwise stable API. Is there a better non-public place for this utility method? I'm asking because I'm genuinely not sure what Hadoop norms are for API changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

In hadoop-common, new public methods on an otherwise stable class are usually marked with @InterfaceStability.Evolving so the method can evolve without changing the class’s stability. Path is already @InterfaceAudience.Public and @InterfaceStability.Stable, so I added @InterfaceStability.Evolving on both ensureDirectoryUri(URI) and asDirectory().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping them on public Path gives callers a single, clear API for “directory URI for this path” (e.g. getWorkingDirectory().asDirectory().toUri().resolve("x")) instead of string hacks. If the project prefers these as package-private or on an internal helper, I can move them.

*
* @return a Path with the same location and a directory-style URI
*/
public Path asDirectory() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question about API changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants