Skip to content

Commit 10356e7

Browse files
author
Brian Burkhalter
committed
8298303: (fs) temporarily remove Path.getExtension
Reviewed-by: smarks, alanb
1 parent 3b8c7ef commit 10356e7

File tree

2 files changed

+1
-143
lines changed

2 files changed

+1
-143
lines changed

src/java.base/share/classes/java/nio/file/Path.java

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* file system. {@code Path} defines the {@link #getFileName() getFileName},
5151
* {@link #getParent getParent}, {@link #getRoot getRoot}, and {@link #subpath
5252
* subpath} methods to access the path components or a subsequence of its name
53-
* elements, and {@link #getExtension() getExtension} to obtain its extension.
53+
* elements.
5454
*
5555
* <p> In addition to accessing the components of a path, a {@code Path} also
5656
* defines the {@link #resolve(Path) resolve} and {@link #resolveSibling(Path)
@@ -249,63 +249,6 @@ public static Path of(URI uri) {
249249
*/
250250
Path getFileName();
251251

252-
/**
253-
* Returns the file extension of this path's file name as a {@code String}.
254-
* The extension is derived from this {@code Path} by obtaining the
255-
* {@linkplain #getFileName file name element}, deriving its {@linkplain
256-
* #toString string representation}, and then extracting a substring
257-
* determined by the position of a period character ('.', U+002E FULL STOP)
258-
* within the file name string. If the file name element is {@code null},
259-
* or if the file name string does not contain a period character, or if
260-
* the only period in the file name string is its first character, then
261-
* the extension is {@code null}. Otherwise, the extension is the substring
262-
* after the last period in the file name string. If this last period is
263-
* also the last character in the file name string, then the extension is
264-
* {@linkplain String#isEmpty empty}.
265-
*
266-
* @implSpec
267-
* The default implementation is equivalent for this path to:
268-
* <pre>{@code
269-
* int lastPeriod = fileName.lastIndexOf('.');
270-
* if (lastPeriod <= 0)
271-
* return null;
272-
* return (lastPeriod == fileName.length() - 1)
273-
* ? ""
274-
* : fileName.substring(lastPeriod + 1);
275-
* }</pre>
276-
*
277-
* @return the file name extension of this path, which might be the
278-
* empty string, or {@code null} if no extension is found
279-
*
280-
* @since 20
281-
*/
282-
default String getExtension() {
283-
Path fileName = getFileName();
284-
if (fileName == null)
285-
return null;
286-
287-
String fileNameString = fileName.toString();
288-
int length = fileNameString.length();
289-
290-
// An empty or unity length file name string has a null extension
291-
if (length > 1) {
292-
int lastPeriodIndex = fileNameString.lastIndexOf('.');
293-
294-
// Indeterminate if there is no period character or
295-
// only the first character is a period character
296-
if (lastPeriodIndex > 0) {
297-
if (lastPeriodIndex == length - 1) {
298-
// empty string
299-
return "";
300-
} else {
301-
return fileNameString.substring(lastPeriodIndex + 1);
302-
}
303-
}
304-
}
305-
306-
return null;
307-
}
308-
309252
/**
310253
* Returns the <em>parent path</em>, or {@code null} if this path does not
311254
* have a parent.

test/jdk/java/nio/file/Path/Extensions.java

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)