Why does Path check for the Default FileSystem?

Alan Bateman Alan.Bateman at oracle.com
Tue Mar 23 13:41:32 UTC 2021


On 23/03/2021 13:36, Michael Hall wrote:
> May I ask why the default FileSystem is checked for here?
>
> default File toFile() {
>          if (getFileSystem() == FileSystems.getDefault()) {
>              return new File(toString());
>          } else {
>              throw new UnsupportedOperationException("Path not associated with "
>                      + "default file system.");
>          }
>      }
>
> For my custom DefaultFileSystemProvider I found it necessary to have my own Path class.
> Most of mine is passthrough and for the Path class I keep a proxy platform provider Path that I use for almost all functionality.
> This check now seems to fail this?
> Is it necessary to be the default or would also being for the default ‘file’ scheme be good enough?
A java.io.File cannot represent a file in a custom file system.

If you are running into an issue here then it may suggest that you 
aren't wrapping or unwrapping correctly. What does Path::getFileSystem 
return on your Path implementation?

-Alan


More information about the nio-dev mailing list