JDK-8274883 : (se) Selector.open throws IAE when the default file system provider is changed to a custom provider
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 16,17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • CPU: generic
  • Submitted: 2021-10-07
  • Updated: 2021-12-14
  • Resolved: 2021-12-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18 JDK 19
18 b27Fixed 19Fixed
Related Reports
Relates :  
Description
An attempt to use `SelectorProvider.provider().openSelector()` on Windows when the file system was specified via `-Djava.nio.file.spi.DefaultFileSystemProvider` fails with an exception starting with Java 16. 

To reproduce: on a Windows system, in the JDK root, go to `test/jdk/java/nio/file/spi`, compile `TestProvider.java` and this test class:
```
import java.nio.channels.spi.SelectorProvider;
public class UnixSocketInNonDefaultFS {
    public static void main(String args[]) throws java.io.IOException {
            try {
                    SelectorProvider.provider().openSelector();
            } catch(ExceptionInInitializerError e) {
                    e.getCause().printStackTrace();
            }
    }
}
```
Executing `java  -Djava.nio.file.spi.DefaultFileSystemProvider=TestProvider UnixSocketInNonDefaultFS` produces this output:
```
java.lang.IllegalArgumentException
        at java.base/java.net.UnixDomainSocketAddress.of(UnixDomainSocketAddress.java:168)
        at java.base/java.net.UnixDomainSocketAddress.of(UnixDomainSocketAddress.java:146)
        at java.base/sun.nio.ch.UnixDomainSockets.<clinit>(UnixDomainSockets.java:47)
        at java.base/sun.nio.ch.SelectorProviderImpl.openServerSocketChannel(SelectorProviderImpl.java:101
)
        at java.base/java.nio.channels.ServerSocketChannel.open(ServerSocketChannel.java:176)
        at java.base/sun.nio.ch.PipeImpl.createListener(PipeImpl.java:221)
        at java.base/sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(PipeImpl.java:125)
        at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:83)
        at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:67)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
        at java.base/sun.nio.ch.PipeImpl.<init>(PipeImpl.java:195)
        at java.base/sun.nio.ch.WEPollSelectorImpl.<init>(WEPollSelectorImpl.java:78)
        at java.base/sun.nio.ch.WEPollSelectorProvider.openSelector(WEPollSelectorProvider.java:33)
        at UnixSocketInNonDefaultFS.main(UnixSocketInNonDefaultFS.java:15)
```

Doing the same with JDK11 produces no such exception.

The problem seems to be in the early bail-out during the static initialization of the `UnixDomainSockets.UNNAMED` field even though it isn't used on this code path.
Comments
Changeset: 7217cb78 Author: Maxim Kartashev <maxim.kartashev@jetbrains.com> Committer: Michael McMahon <michaelm@openjdk.org> Date: 2021-12-07 16:59:34 +0000 URL: https://git.openjdk.java.net/jdk/commit/7217cb78789046cfc823b63cacc36f6cf2b825f5
07-12-2021