From 6e73ea20e06cd5e8f5025cf29a39788578619a3a Mon Sep 17 00:00:00 2001 From: czp3009 Date: Wed, 6 Sep 2023 15:58:27 +0800 Subject: [PATCH 1/2] Add metadata for Netty SelectorProviderUtil --- .../4.1.80.Final/reflect-config.json | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/metadata/io.netty/netty-common/4.1.80.Final/reflect-config.json b/metadata/io.netty/netty-common/4.1.80.Final/reflect-config.json index 63f01aad9..19aa2b5eb 100644 --- a/metadata/io.netty/netty-common/4.1.80.Final/reflect-config.json +++ b/metadata/io.netty/netty-common/4.1.80.Final/reflect-config.json @@ -3838,6 +3838,34 @@ } ] }, + { + "condition": { + "typeReachable": "io.netty.channel.socket.nio.NioServerSocketChannel" + }, + "name": "java.nio.channels.spi.SelectorProvider", + "methods": [ + { + "name": "openServerSocketChannel", + "parameterTypes": [ + "java.net.ProtocolFamily" + ] + } + ] + }, + { + "condition": { + "typeReachable": "io.netty.channel.socket.nio.NioSocketChannel" + }, + "name": "java.nio.channels.spi.SelectorProvider", + "methods": [ + { + "name": "openSocketChannel", + "parameterTypes": [ + "java.net.ProtocolFamily" + ] + } + ] + }, { "condition": { "typeReachable": "io.netty.util.internal.logging.Slf4JLoggerFactory" From 0aa9d4c94602caaebc837327b0c03b503c8730f4 Mon Sep 17 00:00:00 2001 From: czp3009 Date: Sun, 21 Jan 2024 16:46:33 +0800 Subject: [PATCH 2/2] add testcase for Netty SelectorProviderUtil --- .../src/test/java/netty/NettyTests.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/src/io.netty/netty-common/4.1.80.Final/src/test/java/netty/NettyTests.java b/tests/src/io.netty/netty-common/4.1.80.Final/src/test/java/netty/NettyTests.java index 5df7cc2b9..a38c1ba22 100644 --- a/tests/src/io.netty/netty-common/4.1.80.Final/src/test/java/netty/NettyTests.java +++ b/tests/src/io.netty/netty-common/4.1.80.Final/src/test/java/netty/NettyTests.java @@ -7,6 +7,9 @@ package netty; import java.io.InputStream; +import java.net.Inet6Address; +import java.nio.channels.UnsupportedAddressTypeException; +import java.nio.channels.spi.SelectorProvider; import java.time.Duration; import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; @@ -56,8 +59,13 @@ import io.netty.util.CharsetUtil; import org.awaitility.Awaitility; import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; +import static io.netty.channel.socket.InternetProtocolFamily.IPv4; +import static io.netty.util.NetUtil.LOCALHOST; + public class NettyTests { private static final int PORT = 8080; @@ -71,6 +79,36 @@ public void noSsl() throws Exception { test(false); } + @Test + void testNioSocketChannel() { + Assumptions.assumeTrue(LOCALHOST instanceof Inet6Address); + + EventLoopGroup group = new NioEventLoopGroup(); + try { + Bootstrap b = new Bootstrap().group(group) + .channelFactory(() -> new NioSocketChannel(SelectorProvider.provider(), IPv4)) + .handler(new LoggingHandler()); + Assertions.assertThrows(UnsupportedAddressTypeException.class, () -> b.bind(LOCALHOST, 7777).sync().channel()); + } finally { + group.shutdownGracefully(); + } + } + + @Test + void testNioServerSocketChannel() { + Assumptions.assumeTrue(LOCALHOST instanceof Inet6Address); + + EventLoopGroup group = new NioEventLoopGroup(); + try { + Bootstrap b = new Bootstrap().group(group) + .channelFactory(() -> new NioServerSocketChannel(SelectorProvider.provider(), IPv4)) + .handler(new LoggingHandler()); + Assertions.assertThrows(UnsupportedAddressTypeException.class, () -> b.bind(LOCALHOST, 7777).sync().channel()); + } finally { + group.shutdownGracefully(); + } + } + private void test(boolean ssl) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup();