<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
I would like to resurrect this topic which has languished for quite a while now. It was discussed for probably decades before my involvement with it. A brief outline of its most recent history is included below. The essence is that it would be good to add a
java.nio.file.Path.getExtension method, and possibly one or more companion methods. General comments on the topic are welcome regardless of whether the included chronology is reviewed. Things to consider include:</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
1) whether a getExtension method ever returns null;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
2) whether a period character is included as the first character of the returned extension;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
3) whether the extension of “foo” (no dot) differs from that of “foo.” (terminal dot).</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
Thanks,</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
Brian</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
--- snip --- TL;DR --- snip ---</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[1] Feb. 2018</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
Path.hasExtension was initially proposed but dropped in favor of Path.getExtension. This method was for the most common cases equivalent to</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
Path path = ...;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
String name = path.getFileName();</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
String extension = name.substring(name.lastIndexOf(“.”) + 1);</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
which is to say the extension is the portion of the file name string after but not including the last period character (dot). This effort faded out.</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[2] Apr. 2021 - Mar. 2022</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
A pull request was proposed and culminated in the proposal of the Path method</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
String getExtension(String defaultExtension)</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
where in the common case the extension is once again the portion of the file name string after the last dot. For degenerate cases the “defaultExtension” parameter would be returned. This effort was superseded by [3].</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[3] Mar. 2022 - Dec. 2022</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
This pull request specified the Path method</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
String getExtension()</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
which in the common case returned the portion of the file name string after the last dot, and in unusual cases either the empty string (terminal dot) or null (no dot). For a time this proposal used Optional but that was dropped as unwieldy. This PR was approved
and integrated.</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[4] Dec. 2022</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
Due primarily to the undesirability of the possibility of a null return value and the lateness of the integration in the development cycle, the API added in [3] was backed out.</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[5] Dec. 22</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
A new issue was filed to track the resumption of eventual work on this topic. This issue suggested that the last dot be included in the extension, e.g., the extension of “image.jpg” would be “.jpg” rather than “jpg” and that the value returned by getExtension
would never be null. It also proposed a complementary method Path.removeExtension which, together with Path.getExtension, would form an invariant</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
Path path = ...;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
assert path.equals(path.removeExtension() + path.getExtension());</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
which would obviate the need to handle a period character explicitly.</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; min-height: 17px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[1] <a href="https://mail.openjdk.org/pipermail/nio-dev/2018-February/004716.html" class="">
https://mail.openjdk.org/pipermail/nio-dev/2018-February/004716.html</a></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[2] <a href="https://github.com/openjdk/jdk/pull/2319" class="">https://github.com/openjdk/jdk/pull/2319</a></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[3] <a href="https://github.com/openjdk/jdk/pull/8066" class="">https://github.com/openjdk/jdk/pull/8066</a></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[4] <a href="https://github.com/openjdk/jdk/pull/11566" class="">https://github.com/openjdk/jdk/pull/11566</a></div>
<div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal;" class="">
[5] <a href="https://bugs.openjdk.org/browse/JDK-8298318" class="">https://bugs.openjdk.org/browse/JDK-8298318</a></div>
</body>
</html>