Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8278688 | 19 | Michael McMahon | P4 | Resolved | Fixed | team |
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.
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.
- backported by
-
JDK-8278688 (se) Selector.open throws IAE when the default file system provider is changed to a custom provider
-
- Resolved
-
- relates to
-
JDK-8245194 Unix domain socket channel implementation
-
- Resolved
-