Repository: netty/netty
Issue: In netty-4.1.28.Final version, an error occurs when running on jdk6.

### Actual behavior
```
io.netty.channel.ChannelException: Unable to create Channel from class class io.netty.channel.socket.nio.NioSocketChannel
Caused by: java.lang.NoClassDefFoundError: java/nio/channels/NetworkChannel
	at io.netty.channel.socket.nio.NioSocketChannel.<init>(NioSocketChannel.java:105)
	at io.netty.channel.socket.nio.NioSocketChannel.<init>(NioSocketChannel.java:94)
	at io.netty.channel.socket.nio.NioSocketChannel.<init>(NioSocketChannel.java:87)
	at io.netty.channel.socket.nio.NioSocketChannel.<init>(NioSocketChannel.java:80)
	... 32 more
Caused by: java.lang.ClassNotFoundException: java.nio.channels.NetworkChannel
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
```

### Steps to reproduce
```
// run following test on jvm6

    @Test
    public void listenerTest() throws Exception {
        Bootstrap bootstrap = createBootstrap();
        Channel channel = bootstrap.connect(host, port).sync().channel();

    }

    public Bootstrap createBootstrap() {
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(workerGroup).channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new HttpClientCodec());
                        ch.pipeline().addLast(new HttpObjectAggregator(65535));
                    }
                });
        return bootstrap;
    }
```

### Netty version
netty-4.1.28.Final

### JVM version (e.g. `java -version`)
1.6.0_45

### OS version (e.g. `uname -a`)
Windows10,  CentOS 6.6


I think this issue is problem, but I'm not sure.
If this issue is problem, May I make a correction?

Issue comments:
@koo-taejin PTAL https://github.com/netty/netty/pull/8168

Pull request review comments:
Just use

return isSupported() && option instanceof NioChannelOption
I have corrected what you said. :)

Patch that resolved the issue:
diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java
index 74431791ce4..e6fec4861ec 100644
--- a/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java
+++ b/transport/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java
@@ -462,10 +462,19 @@ protected Executor prepareToClose() {
     }
 
     private final class NioSocketChannelConfig extends DefaultSocketChannelConfig {
+
+        private final SocketChannelOptionHelper socketChannelOptionHelper;
         private volatile int maxBytesPerGatheringWrite = Integer.MAX_VALUE;
+
         private NioSocketChannelConfig(NioSocketChannel channel, Socket javaSocket) {
             super(channel, javaSocket);
             calculateMaxBytesPerGatheringWrite();
+
+            if (PlatformDependent.javaVersion() >= 7) {
+                this.socketChannelOptionHelper = new NioChannelOptionHelper();
+            } else {
+                this.socketChannelOptionHelper = new DisabledOptionHelper();
+            }
         }
 
         @Override
@@ -482,16 +491,16 @@ public NioSocketChannelConfig setSendBufferSize(int sendBufferSize) {
 
         @Override
         public <T> boolean setOption(ChannelOption<T> option, T value) {
-            if (PlatformDependent.javaVersion() >= 7 && option instanceof NioChannelOption) {
-                return NioChannelOption.setOption(jdkChannel(), (NioChannelOption<T>) option, value);
+            if (socketChannelOptionHelper.isSupported(option)) {
+                return socketChannelOptionHelper.setOption(jdkChannel(), option, value);
             }
             return super.setOption(option, value);
         }
 
         @Override
         public <T> T getOption(ChannelOption<T> option) {
-            if (PlatformDependent.javaVersion() >= 7 && option instanceof NioChannelOption) {
-                return NioChannelOption.getOption(jdkChannel(), (NioChannelOption<T>) option);
+            if (socketChannelOptionHelper.isSupported(option)) {
+                return socketChannelOptionHelper.getOption(jdkChannel(), option);
             }
             return super.getOption(option);
         }
@@ -499,8 +508,8 @@ public <T> T getOption(ChannelOption<T> option) {
         @SuppressWarnings("unchecked")
         @Override
         public Map<ChannelOption<?>, Object> getOptions() {
-            if (PlatformDependent.javaVersion() >= 7) {
-                return getOptions(super.getOptions(), NioChannelOption.getOptions(jdkChannel()));
+            if (socketChannelOptionHelper.isSupported()) {
+                return getOptions(super.getOptions(), socketChannelOptionHelper.getOptions(jdkChannel()));
             }
             return super.getOptions();
         }
@@ -525,4 +534,82 @@ private SocketChannel jdkChannel() {
             return ((NioSocketChannel) channel).javaChannel();
         }
     }
+
+    private interface SocketChannelOptionHelper {
+
+        boolean isSupported();
+
+        boolean isSupported(ChannelOption option);
+
+        <T> boolean setOption(SocketChannel channel, ChannelOption<T> option, T value);
+
+        <T> T getOption(SocketChannel channel, ChannelOption<T> option);
+
+        ChannelOption[] getOptions(SocketChannel channel);
+    }
+
+    private final class DisabledOptionHelper implements SocketChannelOptionHelper {
+
+        @Override
+        public boolean isSupported() {
+            return false;
+        }
+
+        @Override
+        public boolean isSupported(ChannelOption option) {
+            return false;
+        }
+
+        @Override
+        public <T> boolean setOption(SocketChannel channel, ChannelOption<T> option, T value) {
+            throw new IllegalArgumentException("DisabledOptionHelper");
+        }
+
+        @Override
+        public <T> T getOption(SocketChannel channel, ChannelOption<T> option) {
+            throw new IllegalArgumentException("DisabledOptionHelper");
+        }
+
+        @Override
+        public ChannelOption[] getOptions(SocketChannel channel) {
+            throw new IllegalArgumentException("DisabledOptionHelper");
+        }
+    }
+
+    private final class NioChannelOptionHelper implements SocketChannelOptionHelper {
+
+        @Override
+        public boolean isSupported() {
+            return PlatformDependent.javaVersion() >= 7;
+        }
+
+        @Override
+        public boolean isSupported(ChannelOption option) {
+            return isSupported() && option instanceof NioChannelOption;
+        }
+
+        private void validate(ChannelOption option) {
+            if (!isSupported(option)) {
+                throw new IllegalArgumentException("Not supported ChannelOption");
+            }
+        }
+
+        @Override
+        public <T> boolean setOption(SocketChannel channel, ChannelOption<T> option, T value) {
+            validate(option);
+            return NioChannelOption.setOption(channel, (NioChannelOption<T>) option, value);
+        }
+
+        @Override
+        public <T> T getOption(SocketChannel channel, ChannelOption<T> option) {
+            validate(option);
+            return NioChannelOption.getOption(channel, (NioChannelOption<T>) option);
+        }
+
+        @Override
+        public ChannelOption[] getOptions(SocketChannel channel) {
+            return NioChannelOption.getOptions(channel);
+        }
+    }
+
 }


Test patch: