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

Brian Burkhalter bpb at openjdk.java.net
Thu Apr 21 21:56:26 UTC 2022


On Thu, 21 Apr 2022 21:23:50 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> src/java.base/share/classes/java/nio/file/Path.java line 372:
>> 
>>> 370:         int dotIndex = extension.lastIndexOf('.');
>>> 371:         if (dotIndex > 0)
>>> 372:             throw new IllegalArgumentException();
>> 
>> Can this be stricter and not include a conditional "."
>> It would be more consistent to define the extension as never including the ".".
>
> That would be fine with me and would simplify the code.

Actually, it might be better to prohibit a leading "." but allow them elsewhere, except possibly a trailing ".". This would allow for example `path.replaceExtension("tar.gz")` to return `something.tar.gz` if `path` is `something.tar`.

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

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


More information about the nio-dev mailing list