RFR: 8297814: (fs) Re-visit Path.getExtension return value
Daniel Fuchs
dfuchs at openjdk.org
Tue Dec 6 19:08:20 UTC 2022
On Tue, 6 Dec 2022 18:15:15 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> Revise `java.nio.file.Path::getExtension` never to return `null` and to simplify implementing other path manipulations such as removing and replacing the file name extension.
src/java.base/share/classes/java/nio/file/Path.java line 278:
> 276: * return "";
> 277: * else if (lastPeriod == fileName.length() - 1)
> 278: * return ".";
I believe you could remove these two lines (277-278) - as the case where the last period is the last character in the string should now fold into the case where it is followed by some (non-period) characters.
src/java.base/share/classes/java/nio/file/Path.java line 305:
> 303: // the extension is "." if the last dot is the last character
> 304: if (lastDot == fileNameString.length() - 1) // lastDot > 0
> 305: return ".";
Although this is not needed it's probably a good optimization.
-------------
PR: https://git.openjdk.org/jdk/pull/11545
More information about the nio-dev
mailing list