RFR: 8274883: (se) Selector.open throws IAE when the default file system provider is changed to a custom provider

Alan Bateman alanb at openjdk.java.net
Mon Dec 6 13:44:22 UTC 2021


On Mon, 6 Dec 2021 13:19:54 GMT, Maxim Kartashev <duke at openjdk.java.net> wrote:

> The gist of the problem: when a file system is specified via `-Djava.nio.file.spi.DefaultFileSystemProvider`, a call to `SelectorProvider.provider().openSelector()` ends with a throw on Windows.
> 
> There are two distinct components to the problem:
> 
> 1. `ExceptionInInitializerError` is thrown during the static initialization of the `UnixDomainSockets.UNNAMED` field even though it isn't used on this code path (see `UnixDomainSocketAddress.of()` that throws `IllegalArgumentException` if invoked on a path from a non-default file system). 
> This is fixed by lazy-initializing the static member `UNNAMED` of `UnixDomainSockets` so that this initialization doesn't throw unless actually used.
> 
> 2. `IllegalArgumentException` is thrown by `UnixDomainSocketAddress.of()`  later on when `ServerSocketChannel` tries to use Windows version of `PipeImpl` and its method `createListener()` specifically. That `PipeImpl` probes for the availability of Unix Domain Sockets by trying to bind to a unique temporary name. That call throws `IAE` when a non-default Java file system is installed while the probing code (`PipeImpl.createListener()`) only expects `UnsupportedOperationException` or `IOException`.
> The fix is to re-throw `UOE` instead of `IAE` in `UnixDomainSockets.genrateTempName()`. This is more consistent with the definition of the exception purpose ("requested operation is not supported"). So with this change, a loopback network socket will be used to implement a pipe on a non-default Java file system. Also, pipes do not rely on the default Java file system on other platforms (Linux, MacOS) as well.
> 
> Tested by running `jtreg:test/jdk/java/nio` on Window, MacOS, and Linux.

The JBS issue is assigned to @Michael-Mc-Mahon, might need to check if he already has a patch this for too.

src/java.base/share/classes/sun/nio/ch/UnixDomainSockets.java line 47:

> 45:     private UnixDomainSockets() { }
> 46: 
> 47:     private static class UNNAMEDHolder {

Let's rename this to UnamedHolder to avoid this strange class name.

src/java.base/share/classes/sun/nio/ch/UnixDomainSockets.java line 143:

> 141:             throw new BindException("Invalid temporary directory");
> 142:         } catch (IllegalArgumentException e) {
> 143:             throw new UnsupportedOperationException("Unix Domain Sockets not supported on non-default file system");

There should be no need to catch IAE here, instead you can check the provider.

src/java.base/share/classes/sun/nio/ch/UnixDomainSockets.java line 186:

> 184:     }
> 185: 
> 186:     static UnixDomainSocketAddress getUNNAMED() {

Can you rename this to unnamed() and move it up with the other package default static methods?

-------------

Changes requested by alanb (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/6722


More information about the nio-dev mailing list