Why does Path check for the Default FileSystem?
Michael Hall
mik3hall at gmail.com
Tue Mar 23 13:47:06 UTC 2021
> On Mar 23, 2021, at 8:41 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>
> 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
us.hall.trz.osx.MacFileSystem at 4e0e2f2a
My own Default one. Maybe custom is the wrong word and means something else.
My Default Path class has…
@Override
public final File toFile() {
return proxy.toFile();
}
Where proxy is an instance for the same file obtained using the platform provider. The code as-is objects to me falling back to this Path provider. Which effectively makes passthrough impossible.
More information about the nio-dev
mailing list