United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-5029353 : File.isHidden() produces unexpected results for return values of File.rootFiles()

Details
Type:
Bug
Submit Date:
2004-04-09
Status:
Open
Updated Date:
2008-11-07
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
windows_2000
Sub-Component:
java.io
CPU:
x86
Priority:
P4
Resolution:
Unresolved
Affected Versions:
6
Targeted Versions:

Related Reports

Sub Tasks

Description
Name: rmT116609			Date: 04/08/2004


FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
and java 1.4.1

java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
please run this code and check your results

File[] rootFiles = File.listRoots();
for (int i = 0; i < rootFiles.length; i++) {
    System.out.println(rootFiles[i].getAbsolutePath() + " > isHidden:" + rootFiles[i].isHidden());
}

this is my result:

A:\ > isHidden:false
C:\ > isHidden:true
D:\ > isHidden:false
E:\ > isHidden:true
H:\ > isHidden:false
P:\ > isHidden:false
R:\ > isHidden:false
S:\ > isHidden:false


A is the floppy drive OK
C is a local drive in the pc ERROR - why is this drive hidden
D is the cd drive OK
E is a local drive in the pc ERROR - why is this drive hidden
H is a drive in the LAN OK
P is a drive in the LAN OK
R is a drive in the LAN OK
S is a drive in the LAN OK

why are the local drives hidden???

here are results of other java users:

Just tested this on NT using Jdk 1.3. Results ...

A:\ > isHidden:false

C:\ > isHidden:true

D:\ > isHidden:true

E:\ > isHidden:false

G:\ > isHidden:false

H:\ > isHidden:false

K:\ > isHidden:false

N:\ > isHidden:false

O:\ > isHidden:false

Z:\ > isHidden:false

D and H are local drives.
-------------------------------------

My results under win2000/jdk1.4.1 look weird too:

A:\ > isHidden:false

C:\ > isHidden:true // LOCAL DRIVE!

D:\ > isHidden:true // LOCAL DRIVE!

E:\ > isHidden:false

---------------------------------------

Here are my results:
(NT4 Server SP6)

A:\ > isHidden:false
C:\ > isHidden:true
D:\ > isHidden:true
F:\ > isHidden:true
I:\ > isHidden:false
M:\ > isHidden:true
P:\ > isHidden:true
T:\ > isHidden:true
Y:\ > isHidden:false

c:,d:,f: are local. i: is a mapped folder on local drive f:, and y: is a SUBST-ed folder on d: drive. All other (except a: of course) are on LAN.




please look to this thread in the java forum: http://forum.java.sun.com/thread.jsp?forum=31&thread=419050&tstart=0&trange=15


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test case provided.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A:\ > isHidden:false
C:\ > isHidden:true
D:\ > isHidden:false
E:\ > isHidden:true
H:\ > isHidden:false
P:\ > isHidden:false
R:\ > isHidden:false
S:\ > isHidden:false


A is the floppy drive OK
C is a local drive in the pc ERROR - why is this drive hidden
D is the cd drive OK
E is a local drive in the pc ERROR - why is this drive hidden
H is a drive in the LAN OK
P is a drive in the LAN OK
R is a drive in the LAN OK
S is a drive in the LAN OK

why are the local drives hidden???

here are results of other java users:

Just tested this on NT using Jdk 1.3. Results ...

A:\ > isHidden:false

C:\ > isHidden:true

D:\ > isHidden:true

E:\ > isHidden:false

G:\ > isHidden:false

H:\ > isHidden:false

K:\ > isHidden:false

N:\ > isHidden:false

O:\ > isHidden:false

Z:\ > isHidden:false

D and H are local drives.
-------------------------------------

My results under win2000/jdk1.4.1 look weird too:

A:\ > isHidden:false

C:\ > isHidden:true // LOCAL DRIVE!

D:\ > isHidden:true // LOCAL DRIVE!

E:\ > isHidden:false

---------------------------------------

Here are my results:
(NT4 Server SP6)

A:\ > isHidden:false
C:\ > isHidden:true
D:\ > isHidden:true
F:\ > isHidden:true
I:\ > isHidden:false
M:\ > isHidden:true
P:\ > isHidden:true
T:\ > isHidden:true
Y:\ > isHidden:false

c:,d:,f: are local. i: is a mapped folder on local drive f:, and y: is a SUBST-ed folder on d: drive. All other (except a: of course) are on LAN.

ACTUAL -
A:\ > isHidden:false
C:\ > isHidden:true
D:\ > isHidden:false
E:\ > isHidden:true
H:\ > isHidden:false
P:\ > isHidden:false
R:\ > isHidden:false
S:\ > isHidden:false


A is the floppy drive OK
C is a local drive in the pc ERROR - why is this drive hidden
D is the cd drive OK
E is a local drive in the pc ERROR - why is this drive hidden
H is a drive in the LAN OK
P is a drive in the LAN OK
R is a drive in the LAN OK
S is a drive in the LAN OK

why are the local drives hidden???

here are results of other java users:

Just tested this on NT using Jdk 1.3. Results ...

A:\ > isHidden:false

C:\ > isHidden:true

D:\ > isHidden:true

E:\ > isHidden:false

G:\ > isHidden:false

H:\ > isHidden:false

K:\ > isHidden:false

N:\ > isHidden:false

O:\ > isHidden:false

Z:\ > isHidden:false

D and H are local drives.
-------------------------------------

My results under win2000/jdk1.4.1 look weird too:

A:\ > isHidden:false

C:\ > isHidden:true // LOCAL DRIVE!

D:\ > isHidden:true // LOCAL DRIVE!

E:\ > isHidden:false

---------------------------------------

Here are my results:
(NT4 Server SP6)

A:\ > isHidden:false
C:\ > isHidden:true
D:\ > isHidden:true
F:\ > isHidden:true
I:\ > isHidden:false
M:\ > isHidden:true
P:\ > isHidden:true
T:\ > isHidden:true
Y:\ > isHidden:false

c:,d:,f: are local. i: is a mapped folder on local drive f:, and y: is a SUBST-ed folder on d: drive. All other (except a: of course) are on LAN.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;

class Test {

public static void main(String args[]) {

File[] rootFiles = File.listRoots();
for (int i = 0; i < rootFiles.length; i++) {
    System.out.println(rootFiles[i].getAbsolutePath() + " > isHidden:" + rootFiles[i].isHidden());
}

}
}
---------- END SOURCE ----------
(Incident Review ID: 190316) 
======================================================================

                                    

Comments
EVALUATION

This is still an issue in jdk7. The simplest solution is to ignore the DOS hidden attributes for directories (as the hidden attribute has different semantics on directories). The new file system API (java.nio.file) does not suffer from this issue.
                                     
2009-02-18
EVALUATION

As Martin noted, GetVolumeNameForVolumeMountPoint can be used to get volume name on some newer versions of Windows. However the attributes that GetFileAttributes returns for a volume are unexpected. For example, suppose we have a File to represent "C:\". GetVolumeNameForVolumeMountPoint gives the volume name "\\?\Volume{b2f91ca0-e03f-11d8-bfef-806d6172696f}\" (unique volume names take the form "\\?\Volume{GUID}\"). If we call GetFileAttributes on this then the returned attributes have the hidden bit set so the isHidden() method will still return true.
                                     
2005-08-29
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-06-14
EVALUATION

This passage from

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/getfileattributes.asp

may be relevant:

When GetFileAttributes is called on a directory containing a volume mount point, the file attributes returned are those of the directory where the volume mount point is set, not those of the root directory in the target mounted volume. To obtain the file attributes of the mounted volume, call GetVolumeNameForVolumeMountPoint to obtain the name of the target volume. Then use the resulting name in a call to GetFileAttributes. The results will be the attributes of the root directory on the target volume.

###@###.### 2004-04-09

The Windows "attrib" command exhibits similar confusion about
root directories.

$ attrib C:\\\\.
File not found - C:\.
$ attrib C:\\\\winnt
A          C:\WINNT

We can fix this by checking directories for mount-point-hood,
and then invoking special handling for them.

###@###.### 2004-04-19
                                     
2004-04-19



Hardware and Software, Engineered to Work Together