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

Brian Burkhalter bpb at openjdk.java.net
Wed Mar 30 23:28:55 UTC 2022


On Fri, 29 Jan 2021 22:22:39 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> src/java.base/share/classes/java/nio/file/Path.java line 278:
>> 
>>> 276:         // Indeterminate if name is too short or equal to "..".
>>> 277:         if (length > 1 && !name.equals("..")) {
>>> 278:             int lastDotIndex = name.lastIndexOf('.');
>> 
>> Since there are no strings of length 0..2, is it sufficient to check for length > 2.
>> (Instead of the string compare equals("..").
>
> Nice point! Considering that the strings of length 2 are `.x`, `xy`, and `x.` where `x` and `y` are characters which are not `'.'`, then I concur.

Addressed by commit 7c3d0ff79ee11e6f1e567a21c6f23d3b3dc1c615.

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

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


More information about the nio-dev mailing list