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

UserDefinedFileAttributeView::list() does not work on FreeBSD

XMLWordPrintable

    • generic
    • other

      ADDITIONAL SYSTEM INFORMATION :
      FreeBSD 13.2
      OpenJDK 17.0.8

      A DESCRIPTION OF THE PROBLEM :
      UserDefinedFileAttributeView::list() incorrectly always returns an empty list even if there are xattr.


      A possible reason is that the UnixUserDefinedFileAttributeView assumes that the return value of UnixNativeDispatcher::flistxattr is a list of NULL-terminated C strings. This is true on macOS but not FreeBSD.

      FreeBSD extattr_list_file() encodes Strings differently, without any \0 characters:
      """
      extattr_list_file() returns a list of attributes present in the requested
           namespace. Each list entry consists of a single byte containing the
           length of the attribute name, followed by the attribute name. The attri-
           bute name is not terminated by ASCII 0 (nul).
      """

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the sample code below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      [x]
      1
      (tested on macOS)
      ACTUAL -
      []
      1
      (when running on FreeBSD)

      ---------- BEGIN SOURCE ----------
      import static java.nio.charset.StandardCharsets.*;

      import java.io.File;
      import java.nio.file.Files;
      import java.nio.file.attribute.UserDefinedFileAttributeView;

      public class Main {

      public static void main(String[] args) throws Exception {
      File f = new File("test.txt");
      f.createNewFile();

      UserDefinedFileAttributeView xattr = Files.getFileAttributeView(f.toPath(), UserDefinedFileAttributeView.class);
      xattr.write("x", UTF_8.encode("1"));
      System.out.println(xattr.list());
      System.out.println(xattr.size("x"));
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use lsextattr command and parse the output.

      FREQUENCY : always


            glewis Greg Lewis
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: