Replacing default FileSystemProvider

Michael Hall mik3hall at gmail.com
Sat Mar 20 23:30:39 UTC 2021



> On Mar 20, 2021, at 5:24 PM, Bernd Eckenfels <ecki at zusammenkunft.net> wrote:
> 
> Maybe the provider is resolved against the platform classloader?
> 
> I would think replacing the default provider wasn’t done much before (and not sure if it’s a good idea?). It seems to be good for new form of app sandboxing (but won’t cover old java.io api). So if it only helps for new api consumers, those should allow to specify a base filesystem(root) anyway?
> 

The idea wasn’t to completely replace the default ‘file’ provider but to expose some native API’s through nio attributes. The main use I am remembering. For other purposes it served as a passthrough to the usual default.

So for the FileManager replacement that was being discussed earlier there could be…

        Files.setAttribute(p, "mac_finder:type", new String(b));
        pokeInt(b,0,creator);
        Files.setAttribute(p, "mac_finder:creator", new String(b));

mac_finder would be the API concerned followed by the attribute.
I had attributes for 3 or 4 native API’s.

I have found there does seem to be something version related going on at least…

/usr/libexec/java_home -v 1.8 --exec java -cp .:outputdir/HalfPipe.app/Contents/app/macnio2.jar -Djava.library.path=outputdir/HalfPipe.app/Conents/app -Djava.nio.file.spi.DefaultFileSystemProvider=us.hall.trz.osx.MacFileSystemProvider Test
class us.hall.trz.osx.MacFileSystem
(base) Michaels-MacBook-Pro:halfpipe_jpkg mjh$ /usr/libexec/java_home --exec java -cp .:outputdir/HalfPipe.app/Contents/app/macnio2.jar -Djava.library.path=outputdir/HalfPipe.app/Contents/app -Djava.nio.file.spi.DefaultFileSystemProvider=us.hall.trz.osx.MacFileSystemProvider Test
Exception in thread "main" java.lang.Error: java.lang.NullPointerException: Cannot invoke "java.nio.file.FileSystem.getPath(String, String[])" because the return value of "java.nio.file.FileSystems.getDefault()" is null
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder.getDefaultProvider(FileSystems.java:133)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:102)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder$1.run(FileSystems.java:100)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder.defaultFileSystem(FileSystems.java:100)
	at java.base/java.nio.file.FileSystems$DefaultFileSystemHolder.<clinit>(FileSystems.java:94)
	at java.base/java.nio.file.FileSystems.getDefault(FileSystems.java:182)
...



More information about the nio-dev mailing list