Skip to content

Commit f61ce32

Browse files
sormurasAlan Bateman
authored andcommitted
8255576: (fs) Files.isHidden() throws ArrayIndexOutOfBoundsException (unix)
Reviewed-by: alanb
1 parent fe7672b commit f61ce32

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/java.base/unix/classes/sun/nio/fs/UnixFileSystemProvider.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,14 @@ public boolean isHidden(Path obj) {
352352
UnixPath name = file.getFileName();
353353
if (name == null)
354354
return false;
355-
return (name.asByteArray()[0] == '.');
355+
356+
byte[] path;
357+
if (name.isEmpty()) { // corner case for empty paths
358+
path = name.getFileSystem().defaultDirectory();
359+
} else {
360+
path = name.asByteArray();
361+
}
362+
return path[0] == '.';
356363
}
357364

358365
/**

src/java.base/unix/classes/sun/nio/fs/UnixPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private void initOffsets() {
243243
}
244244

245245
// returns {@code true} if this path is an empty path
246-
private boolean isEmpty() {
246+
boolean isEmpty() {
247247
return path.length == 0;
248248
}
249249

test/jdk/java/nio/file/Files/Misc.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
/* @test
25-
* @bug 4313887 6838333 8005566 8032220 8215467
25+
* @bug 4313887 6838333 8005566 8032220 8215467 8255576
2626
* @summary Unit test for miscellenous methods in java.nio.file.Files
2727
* @library ..
2828
*/
@@ -87,6 +87,9 @@ static void testCreateDirectories(Path tmpdir) throws IOException {
8787
* Tests isHidden
8888
*/
8989
static void testIsHidden(Path tmpdir) throws IOException {
90+
// passing an empty path must not throw any runtime exception
91+
assertTrue(!isHidden(Path.of("")));
92+
9093
assertTrue(!isHidden(tmpdir));
9194

9295
Path file = tmpdir.resolve(".foo");

0 commit comments

Comments
 (0)