Skip to content

Commit d6b0a54

Browse files
vladimirlagunovjbrbot
authored andcommitted
JBR-8965 java.io over nio: improve the performance of IoOverNioFileSystem.getBooleanAttributes
The new code avoids creating unnecessary exceptions.
1 parent 039e666 commit d6b0a54

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/java.base/share/classes/java/io/IoOverNioFileSystem.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,24 @@ private int getBooleanAttributes0(File f) {
640640
// Also, notice that Windows FS does not support Posix attributes, which is expected.
641641
// Checking for Posix attributes first prevents from checking DOS attributes on Linux,
642642
// even though Posix permissions aren't used in this method.
643-
BasicFileAttributes attrs;
644-
try {
645-
attrs = Files.readAttributes(path, PosixFileAttributes.class);
646-
} catch (UnsupportedOperationException _) {
647-
attrs = Files.readAttributes(path, DosFileAttributes.class);
643+
BasicFileAttributes attrs = null;
644+
Set<String> supportedFileAttributeViews = path.getFileSystem().supportedFileAttributeViews();
645+
if (supportedFileAttributeViews.contains("posix")) {
646+
try {
647+
attrs = Files.readAttributes(path, PosixFileAttributes.class);
648+
} catch (UnsupportedOperationException ignored) {
649+
// Nothing.
650+
}
651+
}
652+
if (attrs == null && supportedFileAttributeViews.contains("dos")) {
653+
try {
654+
attrs = Files.readAttributes(path, DosFileAttributes.class);
655+
} catch (UnsupportedOperationException ignored) {
656+
// Nothing.
657+
}
658+
}
659+
if (attrs == null) {
660+
attrs = Files.readAttributes(path, BasicFileAttributes.class);
648661
}
649662

650663
return BA_EXISTS

0 commit comments

Comments
 (0)