Reputation: 11132
I'm about to write a test of a custom FileVisitor which requires the filename of a path.
The documentation of Path's getFileName reads
Returns: a path representing the name of the file or directory, or null if this path has zero elements
Apart from using a mock - which I try to avoid - how do I construct a Path with zero elements?
For all of these, the filename is never null.
Probably it's a behavior of the WindowsFileSystem implementation in Java. Does anyone know if other implementation of FileSystem behave differently and it's actually possible, that getFileName() returns null?
Upvotes: 1
Views: 249
Reputation: 198314
(At least on OSX) java.nio.file.Paths.get('/')
results in such a zero-element sun.nio.fs.UnixPath
.
Upvotes: 1