Search code examples
javafileattributesxattr

Java UserDefinedFileAttributeView null


I'm attempting to use the Files.NIO's UserDefinedFileAttributeView to read & write custom attributes to files (a hash, and two string properties) for use in a media server. I'm running macOS 10.15.4 with APFS, which definitely supports xattr (and I can read & write them from the command line), but I get a NPE when trying to access the properties from Java:

 UserDefinedFileAttributeView view = Files
                .getFileAttributeView(path, UserDefinedFileAttributeView.class);
System.out.println(view.list()); // throws NPE. States that "view" is null

Trying to write gives the same error. What am I missing / what should I be doing different? Ideally, this code would be portable at least between macOS and Windows (Linux might need to specifically enable xattr, so not a big deal).

Thanks!


Solution

  • Answering my own question..

    According to https://bugs.openjdk.java.net/browse/JDK-8040830, the bug has been submitted but never fixed, and the report was closed. So for now, this is not possible on macOS