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

File.isHidden() invokes getBooleanAttributes() making it unnecessarily expensive (unix)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 7
    • core-libs
    • x86
    • linux

      A DESCRIPTION OF THE REQUEST :
      a call to File.isHidden costs a call to getBooleanAttributes, even on Unix:

          public boolean isHidden() {
              SecurityManager security = System.getSecurityManager();
              if (security != null) {
                  security.checkRead(path);
              }
              return ((fs.getBooleanAttributes(this) & FileSystem.BA_HIDDEN) != 0);
          }

      it should end:

        return fs.isHidden(this);

      and UnixFileSystem should change like this:

      + public boolean isHidden(File f) {
      + return f.getName().startsWith(".");
      + }

          public int getBooleanAttributes(File f) {
      - int rv = getBooleanAttributes0(f);
      + return getBooleanAttributes0(f);
      - String name = f.getName();
      - boolean hidden = (name.length() > 0) && (name.charAt(0) == '.');
      - return rv | (hidden ? BA_HIDDEN : 0);
          }

      (or you could just make getBooleanAttributes the native method, as with the Win(32|NT)FileSystem classes.)

      JUSTIFICATION :
      getBooleanAttributes is pretty slow. if you're scanning a large file system, and trying to ignore hidden files in a platform-independent way, the calls to getBooleanAttributes can take 10% of your time, for nothing. this encourages Unix developers to ditch File.isHidden in favor of startsWith("."), and Windows users potentially lose out.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      i'd like to see File.isHidden cost no more on Unix than startsWith("."), but still do the right thing on Windows. one shouldn't pay for what one doesn't use.
      ACTUAL -
      Unix users pay for getBooleanAttributes, the JNI transition, and the stat(2), all for nothing.

      CUSTOMER SUBMITTED WORKAROUND :
      calling startsWith(".") instead of File.isHidden, but that sucks for Windows users, as if their lives weren't bad enough already.

            alanb Alan Bateman
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: