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

Stuart Marks smarks at openjdk.org
Wed Aug 3 22:36:33 UTC 2022


On Wed, 3 Aug 2022 15:37:24 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8057113: Remove API note
>
> src/java.base/share/classes/java/nio/file/Path.java line 297:
> 
>> 295:                 if (lastPeriodIndex == length - 1) {
>> 296:                     // null if all period characters, otherwise empty
>> 297:                     return fileNameString.matches("\\.{" + length + "}") ?
> 
> Using a regular expression here is probably okay or the initial PR but I could imagine this show up in profiles and needing to be re-implemented.

Yeah I don't think we want to use regex here. I'd suggest something like this:

    int lastDot = fileNameString.lastIndexOf('.');
    for (int j = lastDot - 1; j >= 0; j--) {
        if (fileNameString.charAt(j) != '.') {
            return fileNameString.substring(lastDot + 1);
        }
    }
    return null;

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

PR: https://git.openjdk.org/jdk/pull/8066


More information about the nio-dev mailing list