RFR: 8057113: (fs) Path should have a method to obtain the filename extension [v6]

Roger Riggs rriggs at openjdk.java.net
Fri Apr 29 15:57:04 UTC 2022


On Thu, 28 Apr 2022 22:14:30 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Resurrection of the proposal to add a method to obtain the filename extension originated in PR [2319](https://github.com/openjdk/jdk/pull/2319).
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8057113: String getExtension(String defaultExtension) to Optional<String> getExtension() and other changes

I'm still not sure of the "pro's" of considering a file name with a final "." as having no extension (as opposed to an empty one).

I think the API looks good, it might be time to outline a test showing some concrete examples.

src/java.base/share/classes/java/nio/file/Path.java line 378:

> 376:         if (thisExtension == null)
> 377:             return extension.isEmpty() ?
> 378:                 this : fs.getPath(thisPath + "." + extension);

Can this end up with a double dot ".." in the case where the original path ended in in dot?
I.e.

    Path p = Path.of("foo.");
    Path q = p.replaceExtension("bar");

-------------

PR: https://git.openjdk.java.net/jdk/pull/8066


More information about the nio-dev mailing list