Summary
Remove java.nio.file.Path::getExtension
that was added for JDK-8057113.
Problem
Path::getExtension
is still a matter of discussion (cf. JDK-8297814) and it would be dangerous to add it this late in the JDK 20 timeline.
Solution
Remove java.nio.file.Path::getExtension
Specification
--- a/src/java.base/share/classes/java/nio/file/Path.java
+++ b/src/java.base/share/classes/java/nio/file/Path.java
@@ -50,7 +50,7 @@
* file system. {@code Path} defines the {@link #getFileName() getFileName},
* {@link #getParent getParent}, {@link #getRoot getRoot}, and {@link #subpath
* subpath} methods to access the path components or a subsequence of its name
- * elements, and {@link #getExtension() getExtension} to obtain its extension.
+ * elements.
*
* <p> In addition to accessing the components of a path, a {@code Path} also
* defines the {@link #resolve(Path) resolve} and {@link #resolveSibling(Path)
@@ -249,63 +249,6 @@ public static Path of(URI uri) {
*/
Path getFileName();
- /**
- * Returns the file extension of this path's file name as a {@code String}.
- * The extension is derived from this {@code Path} by obtaining the
- * {@linkplain #getFileName file name element}, deriving its {@linkplain
- * #toString string representation}, and then extracting a substring
- * determined by the position of a period character ('.', U+002E FULL STOP)
- * within the file name string. If the file name element is {@code null},
- * or if the file name string does not contain a period character, or if
- * the only period in the file name string is its first character, then
- * the extension is {@code null}. Otherwise, the extension is the substring
- * after the last period in the file name string. If this last period is
- * also the last character in the file name string, then the extension is
- * {@linkplain String#isEmpty empty}.
- *
- * @implSpec
- * The default implementation is equivalent for this path to:
- * <pre>{@code
- * int lastPeriod = fileName.lastIndexOf('.');
- * if (lastPeriod <= 0)
- * return null;
- * return (lastPeriod == fileName.length() - 1)
- * ? ""
- * : fileName.substring(lastPeriod + 1);
- * }</pre>
- *
- * @return the file name extension of this path, which might be the
- * empty string, or {@code null} if no extension is found
- *
- * @since 20
- */
- default String getExtension() {
- Path fileName = getFileName();
- if (fileName == null)
- return null;
-
- String fileNameString = fileName.toString();
- int length = fileNameString.length();
-
- // An empty or unity length file name string has a null extension
- if (length > 1) {
- int lastPeriodIndex = fileNameString.lastIndexOf('.');
-
- // Indeterminate if there is no period character or
- // only the first character is a period character
- if (lastPeriodIndex > 0) {
- if (lastPeriodIndex == length - 1) {
- // empty string
- return "";
- } else {
- return fileNameString.substring(lastPeriodIndex + 1);
- }
- }
- }
-
- return null;
- }
-
/**
* Returns the <em>parent path</em>, or {@code null} if this path does not
* have a parent.
- csr of
-
JDK-8298303 (fs) temporarily remove Path.getExtension
-
- Resolved
-
- relates to
-
JDK-8260738 (fs) Path should have a method to obtain the filename extension
-
- Closed
-
-
JDK-8298224 (fs) Re-visit Path.getExtension return value
-
- Closed
-