0

Using Oracle JDK 1.8.112 on RHEL 6.8, this is producing NullPointerException, on one system but not another:

Files.setPosixFilePermissions(path, PosixFilePermissions.fromString("rwxrwxr-x"));

But, this does not:

PosixFileAttributeView av = Files.getFileAttributeView(path, PosixFileAttributeView.class);
av.setPermissions(EnumSet.of(PosixFilePermission.OWNER_READ
                            , PosixFilePermission.OWNER_WRITE
                            , PosixFilePermission.OWNER_EXECUTE
                            , PosixFilePermission.GROUP_READ
                            , PosixFilePermission.GROUP_WRITE
                            , PosixFilePermission.GROUP_EXECUTE
                            , PosixFilePermission.OTHERS_READ
                            , PosixFilePermission.OTHERS_EXECUTE));

The file permissions and security context are the same for path on both systems. Do you have any idea how that could be?

wdkendall
  • 65
  • 1
  • 8
  • 1
    Looks like ["the attribute view type is not available"](https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#getFileAttributeView(java.nio.file.Path,%20java.lang.Class,%20java.nio.file.LinkOption...)). – Andy Turner Jul 15 '17 at 21:14
  • Perhaps the `path` is null? That's the only reason I can imagine the first one would throw a NPE. Check your expectations with a debugger (or at least a logger). – Elliott Frisch Jul 15 '17 at 21:19
  • Thanks. The attribute view is available. That is what works. setPosixFilePermissions gets NullPointerException. And "path" is not null. – wdkendall Jul 15 '17 at 22:45
  • My wording is confusing. Attribute view being unavailable is not the problem. That is what works. It is setPosixFilePermissions that gets a null pointer exception. – wdkendall Jul 17 '17 at 17:31

0 Answers0