Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6716072
Votes 0
Synopsis File.isHidden() invokes getBooleanAttributes() making it unnecessarily expensive (unix)
Category java:classes_io
Reported Against
Release Fixed
State 11-Closed, duplicate of 4313887, request for enhancement
Priority: 5-Very Low
Related Bugs
Submit Date 18-JUN-2008
Description
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.
Posted Date : 2008-06-18 13:27:51.0
Work Around
N/A
Evaluation
A side effect of the proposal is that the isHidden method would return "true" for cases that the file does not exist or is not accessible. While the method has never specified if it checks the file or not this would be a behavior change that would require careful consideration before implementing.
Posted Date : 2008-06-18 13:49:43.0

Changing behavior after all these years would be risky. Instead, code now use the new file system API where f.toPath().isHidden() will not access the file system on Unix.
Posted Date : 2009-02-16 15:47:19.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang