Skip to content

Commit d57612e

Browse files
committed
8360887: [AIX] getFileAttributeView returns unusable FileAttributeView if UserDefinedFileAttributeView unavailable
1 parent ecd2d83 commit d57612e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/java.base/aix/classes/sun/nio/fs/AixFileSystemProvider.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,24 @@ AixFileStore getFileStore(UnixPath path) throws IOException {
5252
return new AixFileStore(path);
5353
}
5454

55+
static boolean supportsUserDefinedFileAttributeView(Path obj) {
56+
try {
57+
FileStore store = Files.getFileStore(obj);
58+
return store.supportsFileAttributeView(UserDefinedFileAttributeView.class);
59+
} catch (IOException e) {
60+
return false;
61+
}
62+
}
63+
5564
@Override
5665
@SuppressWarnings("unchecked")
5766
public <V extends FileAttributeView> V getFileAttributeView(Path obj,
5867
Class<V> type,
5968
LinkOption... options)
6069
{
6170
if (type == UserDefinedFileAttributeView.class) {
62-
return (V) new AixUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
63-
Util.followLinks(options));
71+
return !supportsUserDefinedFileAttributeView(obj) ? null :
72+
(V) new AixUserDefinedFileAttributeView(UnixPath.toUnixPath(obj), Util.followLinks(options));
6473
}
6574
return super.getFileAttributeView(obj, type, options);
6675
}
@@ -71,8 +80,8 @@ public DynamicFileAttributeView getFileAttributeView(Path obj,
7180
LinkOption... options)
7281
{
7382
if (name.equals("user")) {
74-
return new AixUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
75-
Util.followLinks(options));
83+
return !supportsUserDefinedFileAttributeView(obj) ? null :
84+
new AixUserDefinedFileAttributeView(UnixPath.toUnixPath(obj), Util.followLinks(options));
7685
}
7786
return super.getFileAttributeView(obj, name, options);
7887
}

test/jdk/java/nio/file/attribute/UserDefinedFileAttributeView/Basic.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ public static void main(String[] args) throws IOException {
282282
Path dir = TestUtil.createTemporaryDirectory();
283283
try {
284284
if (!Files.getFileStore(dir).supportsFileAttributeView("user")) {
285+
// check if getFileAttributeView behaves as specified in this case
286+
if (Files.getFileAttributeView(dir, UserDefinedFileAttributeView.class) != null) {
287+
throw new RuntimeException("UserDefinedFileAttributeView not supported, getFileAttributeView should return null");
288+
}
289+
285290
System.out.println("UserDefinedFileAttributeView not supported - skip test");
286291
return;
287292
}

0 commit comments

Comments
 (0)