If you create a Unix domain socket on Windows ( 2019 server) and try to get its file attributes with: Files.readAttributes(p, BasicFileAttributes.class) this will fail with: $ java Foo foo.sock Server: local address = foo.sock Exception in thread "main" java.nio.file.FileSystemException: foo.sock: The file cannot be accessed by the system at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92) at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103) at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108) at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.j ava:53) at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.j ava:38) at java.base/sun.nio.fs.WindowsFileSystemProvider.readAttributes(WindowsFileSystemProvider.java:19 9) at java.base/java.nio.file.Files.readAttributes(Files.java:1843) at Foo.main(Foo.java:18) A test program to generate this is as follows. However, this depends on JEP380 which has not been integrated into 16 yet. A native executable could show it also. $ cat Foo.java import java.io.*; import java.net.*; import java.util.*; import java.nio.*; import java.nio.file.*; import java.nio.file.attribute.*; import java.nio.channels.*; public class Foo { public static void main(String[] args) throws Exception { var server = ServerSocketChannel.open(StandardProtocolFamily.UNIX); String s = new String("foo.sock"); System.out.println(s); Path p = Path.of(s); server.bind(UnixDomainSocketAddress.of(p)); System.out.println("Server: local address = " + server.getLocalAddress()); BasicFileAttributes attrs = Files.readAttributes(p, BasicFileAttributes.class); } } The problem relates to the implementation of Unix domain sockets on Windows as NTFS reparse points, which typically require special handling in user code. Incidentally, Cygwin has the same problem and at times is unable to delete the socket files. So "rm foo.sock" typically fails with a permission error. This can be worked around by doing "cmd /c del foo.sock" from a Cygwin command prompt.
|