RFR: 8298318: (fs) APIs for handling filename extensions [v2]

Brian Burkhalter bpb at openjdk.org
Tue Nov 21 19:00:10 UTC 2023


On Tue, 21 Nov 2023 17:38:44 GMT, Anthony Vanelverdinghe <duke at openjdk.org> wrote:

> My two cents:

Thanks for the comments.

>     * for `foo.`, wouldn't `removeExtension().addExtension(getExtension())` result in `foo`, i.e. the invariant be broken?

It looks like it would be. Another problematic corner case.

>     * for `.gitconfig`, the current implementation of `getExtension()` returns `""` , but according to Windows conventions, the extension is `gitconfig`

And according to the UNIX `FILE(1)` command

$ file --extension .gitconfig 
.gitconfig: ???

there is no extension. Many different tools and APIs were examined in the past and there is no consensus as to whether to include the period character. It's almost a 50-50 split.

>     * both PowerShell and Python (just 2 I tried) include the dot in the extension, and it seems natural to me to have an invariant that `base + extension = filename`. I assume this was discussed at length already though, so I'm just curious about the rationale for excluding the dot?

It has been discussed at length in prior incarnations of this effort. The invariant is an appealing idea.

_My_ rationale for exlcuding the dot is that is analogous to a separator such as `/` or `` and conveys no information on its own. In my own experience in other areas such as media (imaging and video) I have rarely seen the period character included in the extension, and if it was detected it was removed.

>     * has the idea of introducing a new class and adding a method to Path (`getFileName()` is already taken, so I'd propose `filename()`) been explored? For example, recently I needed to work with extensions and ended up with something like below.

This has not been discussed but I doubt it would be a very popular idea. One thing is that it would add complexity and API surface. Another is that OS-specific behavior is not usually codified.

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

PR Comment: https://git.openjdk.org/jdk/pull/16226#issuecomment-1821482681


More information about the nio-dev mailing list