Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7043788

(fs) PosixFileAttributes.owner() or group() throws NPE if owner/group not in passwd/group database

XMLWordPrintable

    • b143
    • generic
    • generic
    • Not verified

      Exception in thread "main" java.lang.NullPointerException
              at java.lang.String.<init>(String.java:602)
              at sun.nio.fs.UnixUserPrincipals.fromGid(UnixUserPrincipals.java:129)
              at sun.nio.fs.UnixFileAttributes.group(UnixFileAttributes.java:187)
              at GroupsTest.main(GroupsTest.java:9)

      To reproduce, create file with numerical owner (group id 12345 is not in /etc/group) and try to read attributes:
      $ touch file
      $ chown :12345 file
      $ java -cp . GroupsTest

      ===
      import java.io.*;
      import java.nio.file.*;
      import java.nio.file.attribute.*;

      public class GroupsTest {
              public static void main(String[] args) throws IOException {
                      File f = new File("file");
                      PosixFileAttributes attrs = Files.readAttributes(f.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
                      System.out.println(attrs.group());
              }
      }
      ===

            alanb Alan Bateman
            nhaustov Nicolay Haustov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: