Shouldn't this code have thrown a FileSystemLoopException instead?

Francis Galiegue fgaliegue at gmail.com
Fri Feb 6 17:24:54 UTC 2015


On Fri, Feb 6, 2015 at 6:20 PM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
[...]
>
> I would expect the exception message to contain something like "Too many
> levels of symbolic links" as that is the error that the kernel should report
> for this case. I see your code just prints the exception name so you might
> not see the detail.
>

Well, it does; but then again this is exactly what I reproached to
FileNotFoundException: you had to peek at the message to get a hint as
to the real reason why the operation failed.

> As I think I've mentioned here before, we've deliberately avoided trying to
> overly specify the exceptions and instead limit it to cases where it would
> be reasonable to recover in a specific scenario. So while we could
> consistently map ELOOP to FileSystemLoopException then it's not clear that
> an application could take recovering action that is different to that of
> catching the more general IOException. Also the main purpose of
> FileSystemLoopException in the API is Files.walk and walkFileTree where it
> is important to detect and report cycles when following links. So I'm not
> saying that we shouldn't do this, it's just not clear that an application or
> library would do anything useful with it.
>

On the other hand, this exception exists, why not use it? I mean, it
has even been _defined_ in the first place, and to my eyes, this is
clearly a scenario where this particular exception should be thrown,
wouldn't you agree?

Also, well, see above.

-- 
Francis Galiegue, fgaliegue at gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/fge/grappa


More information about the nio-dev mailing list