Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/java.base/aix/classes/sun/nio/fs/AixFileSystemProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ AixFileStore getFileStore(UnixPath path) throws IOException {
return new AixFileStore(path);
}

static boolean supportsUserDefinedFileAttributeView(Path obj) {
private static boolean supportsUserDefinedFileAttributeView(UnixPath file) {
try {
FileStore store = Files.getFileStore(obj);
FileStore store = new AixFileStore(file);
return store.supportsFileAttributeView(UserDefinedFileAttributeView.class);
} catch (IOException e) {
return false;
Expand All @@ -68,8 +68,10 @@ public <V extends FileAttributeView> V getFileAttributeView(Path obj,
LinkOption... options)
{
if (type == UserDefinedFileAttributeView.class) {
return !supportsUserDefinedFileAttributeView(obj) ? null :
(V) new AixUserDefinedFileAttributeView(UnixPath.toUnixPath(obj), Util.followLinks(options));
UnixPath file = UnixPath.toUnixPath(obj);
return supportsUserDefinedFileAttributeView(file) ?
(V) new AixUserDefinedFileAttributeView(file, Util.followLinks(options))
: null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try this:

if (type == UserDefinedFileAttributeView.class) { 
    UnixPath file = UnixPath.toUnixPath(obj);
    return supportsUserDefinedFileAttributeView(file) ? ..

That will remove the cast/check from supportsUserDefinedFileAttributeView and also ensure that ProviderMismatchException is thrown if called with a Path from a different provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this version much better. Changed.

}
return super.getFileAttributeView(obj, type, options);
}
Expand All @@ -80,8 +82,10 @@ public DynamicFileAttributeView getFileAttributeView(Path obj,
LinkOption... options)
{
if (name.equals("user")) {
return !supportsUserDefinedFileAttributeView(obj) ? null :
new AixUserDefinedFileAttributeView(UnixPath.toUnixPath(obj), Util.followLinks(options));
UnixPath file = UnixPath.toUnixPath(obj);
return supportsUserDefinedFileAttributeView(file) ?
new AixUserDefinedFileAttributeView(file, Util.followLinks(options))
: null;
}
return super.getFileAttributeView(obj, name, options);
}
Expand Down
30 changes: 15 additions & 15 deletions test/jdk/java/nio/file/FileStore/Basic.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ static void checkWithin1GB(String space, long expected, long actual) {
}
}

static <V extends FileAttributeView> void testFileAttributes(Path file,
Class<V> viewClass,
String viewName) throws IOException {
FileStore store = Files.getFileStore(file);
boolean supported = store.supportsFileAttributeView(viewClass);
assertTrue(store.supportsFileAttributeView(viewName) == supported);
boolean haveView = Files.getFileAttributeView(file, viewClass) != null;
assertTrue(haveView == supported);
}

static void doTests(Path dir) throws IOException {
/**
* Test: Directory should be on FileStore that is writable
Expand Down Expand Up @@ -97,21 +107,11 @@ static void doTests(Path dir) throws IOException {
* Test: File and FileStore attributes
*/
assertTrue(store1.supportsFileAttributeView("basic"));
assertTrue(store1.supportsFileAttributeView(BasicFileAttributeView.class));
assertTrue(store1.supportsFileAttributeView("posix") ==
store1.supportsFileAttributeView(PosixFileAttributeView.class));
assertTrue(store1.supportsFileAttributeView("dos") ==
store1.supportsFileAttributeView(DosFileAttributeView.class));
assertTrue(store1.supportsFileAttributeView("acl") ==
store1.supportsFileAttributeView(AclFileAttributeView.class));
assertTrue(store1.supportsFileAttributeView("user") ==
store1.supportsFileAttributeView(UserDefinedFileAttributeView.class));

// check if getFileAttributeView behaves as specified if the user defined view is unsupported
if (!store1.supportsFileAttributeView(UserDefinedFileAttributeView.class) &&
Files.getFileAttributeView(dir, UserDefinedFileAttributeView.class) != null) {
throw new RuntimeException("UserDefinedFileAttributeView not supported, getFileAttributeView should return null");
}
testFileAttributes(dir, BasicFileAttributeView.class, "basic");
testFileAttributes(dir, PosixFileAttributeView.class, "posix");
testFileAttributes(dir, DosFileAttributeView.class, "dos");
testFileAttributes(dir, AclFileAttributeView.class, "acl");
testFileAttributes(dir, UserDefinedFileAttributeView.class, "user");

/**
* Test: Space atributes
Expand Down