7127235: (fs) NPE in Files.walkFileTree if cached attributes are GC'ed
Rémi Forax
forax at univ-mlv.fr
Thu Jan 5 07:52:49 PST 2012
On 01/05/2012 04:04 PM, Alan Bateman wrote:
>
> This is a faux pas in the implementation of Files.walkFileTree. Where
> the attributes of the files in a directory are read as part of the
> iteration then they are cached, via a weak reference, to avoid
> re-fetching them. Unfortunately this code doesn't check if the
> reference has been cleared which can be lead to a NPE as per the bug
> report. The fix is to trivially check if the reference has been
> cleared. This one is really hard to reproduce and I don't have a
> reliable test case.
>
> -Alan
>
> diff --git a/src/share/classes/java/nio/file/FileTreeWalker.java
> b/src/share/classes/java/nio/file/FileTreeWalker.java
> --- a/src/share/classes/java/nio/file/FileTreeWalker.java
> +++ b/src/share/classes/java/nio/file/FileTreeWalker.java
> @@ -92,7 +92,7 @@ class FileTreeWalker {
> (System.getSecurityManager() == null))
> {
> BasicFileAttributes cached =
> ((BasicFileAttributesHolder)file).get();
> - if (!followLinks || !cached.isSymbolicLink())
> + if (cached != null && (!followLinks ||
> !cached.isSymbolicLink()))
> attrs = cached;
> }
> IOException exc = null;
>
Looks Ok for me but I was not able to read the bug report (not available).
cheers,
Rémi
More information about the nio-dev
mailing list