Skip to content

Commit a98a5e5

Browse files
committed
8360887: (fs) Files.getFileAttributeView returns unusable FileAttributeView if UserDefinedFileAttributeView unavailable (aix)
Reviewed-by: mbaesken Backport-of: 0572b6e
1 parent b245c51 commit a98a5e5

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2013 SAP SE. All rights reserved.
3+
* Copyright (c) 2013, 2025 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -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/FileStore/Basic.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
2222
*/
2323

2424
/* @test
25-
* @bug 4313887 6873621 6979526 7006126 7020517 8264400
25+
* @bug 4313887 6873621 6979526 7006126 7020517 8264400 8360887
2626
* @summary Unit test for java.nio.file.FileStore
2727
* @key intermittent
2828
* @library .. /test/lib
@@ -107,6 +107,12 @@ static void doTests(Path dir) throws IOException {
107107
assertTrue(store1.supportsFileAttributeView("user") ==
108108
store1.supportsFileAttributeView(UserDefinedFileAttributeView.class));
109109

110+
// check if getFileAttributeView behaves as specified if the user defined view is unsupported
111+
if (!store1.supportsFileAttributeView(UserDefinedFileAttributeView.class) &&
112+
Files.getFileAttributeView(dir, UserDefinedFileAttributeView.class) != null) {
113+
throw new RuntimeException("UserDefinedFileAttributeView not supported, getFileAttributeView should return null");
114+
}
115+
110116
/**
111117
* Test: Space atributes
112118
*/

0 commit comments

Comments
 (0)