File Attributes from DirectoryStream (WindowsPathWithAttributes)?

Alan Bateman Alan.Bateman at oracle.com
Mon Aug 27 06:43:10 UTC 2018


On 10/08/2018 07:05, Bernd Eckenfels wrote:
> Hello,
>
> in sun.nio.fs.WindowsDirectoryStream I see that the code which iterates the Directory goes to some length to retain the file attributes returned from that function (by attaching them to a WindowsPathWithAttributes (aka BasicFileAttributesHolder).
>
> And indeed I can see that class in my DirectroyStream Iterator or Filter. However I do not see that the normal WindowsFilesystemProvider (or actually WindowsFileAttributes#get() check for instances of that. This way None of the Files.getAttributeView seem to Benefit from that.
>
> So I wonder is this missing or is there some other way you are supposed to work with this cached Attributes?
>
> For 8 I can work with instanceof, but that might no longer be an Option with JPMS.
>
The caching you have found is for use when walking a file tree 
(walkFileTree and walk methods). It is not valid to cache attributes as 
you are suggesting as the file may have changed or may even be a 
different file.

If I read your mail correctly then you making direct use of sun.nio.fs.* 
classes. These are JDK internal and no guarantee that they won't change 
at any time. Also you will have issues at both compile-time and run time 
once the java.base module is fully encapsulated.

-Alan


More information about the nio-dev mailing list