File tree Expand file tree Collapse file tree 3 files changed +13
-3
lines changed
src/java.base/unix/classes/sun/nio/fs
test/jdk/java/nio/file/Files Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -352,7 +352,14 @@ public boolean isHidden(Path obj) {
352
352
UnixPath name = file .getFileName ();
353
353
if (name == null )
354
354
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 ] == '.' ;
356
363
}
357
364
358
365
/**
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ private void initOffsets() {
243
243
}
244
244
245
245
// returns {@code true} if this path is an empty path
246
- private boolean isEmpty () {
246
+ boolean isEmpty () {
247
247
return path .length == 0 ;
248
248
}
249
249
Original file line number Diff line number Diff line change 22
22
*/
23
23
24
24
/* @test
25
- * @bug 4313887 6838333 8005566 8032220 8215467
25
+ * @bug 4313887 6838333 8005566 8032220 8215467 8255576
26
26
* @summary Unit test for miscellenous methods in java.nio.file.Files
27
27
* @library ..
28
28
*/
@@ -87,6 +87,9 @@ static void testCreateDirectories(Path tmpdir) throws IOException {
87
87
* Tests isHidden
88
88
*/
89
89
static void testIsHidden (Path tmpdir ) throws IOException {
90
+ // passing an empty path must not throw any runtime exception
91
+ assertTrue (!isHidden (Path .of ("" )));
92
+
90
93
assertTrue (!isHidden (tmpdir ));
91
94
92
95
Path file = tmpdir .resolve (".foo" );
You can’t perform that action at this time.
0 commit comments