Repository: netty/netty
Issue: EpollSocketChannelConfig is repeating the channel field 3x
Labels: cleanup

The`EpollSocketChannelConfig` class is repeating the `channel` field 3x through inheritance. The field has also protected and package-private visibility in the super classes which is potentially bug-prone.

![screenshot from 2018-09-27 13-46-22](https://user-images.githubusercontent.com/191635/46164564-542fd200-c25c-11e8-988b-0fa7f3d14eea.png)


### Expected behavior

### Actual behavior

### Steps to reproduce

### Minimal yet complete reproducer code (or URL to code)

### Netty version

### JVM version (e.g. `java -version`)

### OS version (e.g. `uname -a`)


Issue comments:
@rkapsi doh... Want to send over a pr ?
@normanmaurer consider it done (hopefully tomorrow morning)

Pull request review comments:

Patch that resolved the issue:
diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollChannelConfig.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollChannelConfig.java
index c0cceb255af..2d2610c0e27 100644
--- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollChannelConfig.java
+++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollChannelConfig.java
@@ -29,12 +29,10 @@
 import static io.netty.channel.unix.Limits.SSIZE_MAX;
 
 public class EpollChannelConfig extends DefaultChannelConfig {
-    final AbstractEpollChannel channel;
     private volatile long maxBytesPerGatheringWrite = SSIZE_MAX;
 
     EpollChannelConfig(AbstractEpollChannel channel) {
         super(channel);
-        this.channel = channel;
     }
 
     @Override
@@ -136,7 +134,7 @@ public EpollChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator
      * {@link EpollMode#LEVEL_TRIGGERED}.
      */
     public EpollMode getEpollMode() {
-        return channel.isFlagSet(Native.EPOLLET)
+        return ((AbstractEpollChannel) channel).isFlagSet(Native.EPOLLET)
                 ? EpollMode.EDGE_TRIGGERED : EpollMode.LEVEL_TRIGGERED;
     }
 
@@ -156,11 +154,11 @@ public EpollChannelConfig setEpollMode(EpollMode mode) {
             switch (mode) {
             case EDGE_TRIGGERED:
                 checkChannelNotRegistered();
-                channel.setFlag(Native.EPOLLET);
+                ((AbstractEpollChannel) channel).setFlag(Native.EPOLLET);
                 break;
             case LEVEL_TRIGGERED:
                 checkChannelNotRegistered();
-                channel.clearFlag(Native.EPOLLET);
+                ((AbstractEpollChannel) channel).clearFlag(Native.EPOLLET);
                 break;
             default:
                 throw new Error();
@@ -179,7 +177,7 @@ private void checkChannelNotRegistered() {
 
     @Override
     protected final void autoReadCleared() {
-        channel.clearEpollIn();
+        ((AbstractEpollChannel) channel).clearEpollIn();
     }
 
     final void setMaxBytesPerGatheringWrite(long maxBytesPerGatheringWrite) {
diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannelConfig.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannelConfig.java
index fbc44c1bcc1..f3de6ac5947 100644
--- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannelConfig.java
+++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannelConfig.java
@@ -31,12 +31,10 @@
 
 public final class EpollDatagramChannelConfig extends EpollChannelConfig implements DatagramChannelConfig {
     private static final RecvByteBufAllocator DEFAULT_RCVBUF_ALLOCATOR = new FixedRecvByteBufAllocator(2048);
-    private final EpollDatagramChannel datagramChannel;
     private boolean activeOnOpen;
 
     EpollDatagramChannelConfig(EpollDatagramChannel channel) {
         super(channel);
-        datagramChannel = channel;
         setRecvByteBufAllocator(DEFAULT_RCVBUF_ALLOCATOR);
     }
 
@@ -219,7 +217,7 @@ public EpollDatagramChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead)
     @Override
     public int getSendBufferSize() {
         try {
-            return datagramChannel.socket.getSendBufferSize();
+            return ((EpollDatagramChannel) channel).socket.getSendBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -228,7 +226,7 @@ public int getSendBufferSize() {
     @Override
     public EpollDatagramChannelConfig setSendBufferSize(int sendBufferSize) {
         try {
-            datagramChannel.socket.setSendBufferSize(sendBufferSize);
+            ((EpollDatagramChannel) channel).socket.setSendBufferSize(sendBufferSize);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -238,7 +236,7 @@ public EpollDatagramChannelConfig setSendBufferSize(int sendBufferSize) {
     @Override
     public int getReceiveBufferSize() {
         try {
-            return datagramChannel.socket.getReceiveBufferSize();
+            return ((EpollDatagramChannel) channel).socket.getReceiveBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -247,7 +245,7 @@ public int getReceiveBufferSize() {
     @Override
     public EpollDatagramChannelConfig setReceiveBufferSize(int receiveBufferSize) {
         try {
-            datagramChannel.socket.setReceiveBufferSize(receiveBufferSize);
+            ((EpollDatagramChannel) channel).socket.setReceiveBufferSize(receiveBufferSize);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -257,7 +255,7 @@ public EpollDatagramChannelConfig setReceiveBufferSize(int receiveBufferSize) {
     @Override
     public int getTrafficClass() {
         try {
-            return datagramChannel.socket.getTrafficClass();
+            return ((EpollDatagramChannel) channel).socket.getTrafficClass();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -266,7 +264,7 @@ public int getTrafficClass() {
     @Override
     public EpollDatagramChannelConfig setTrafficClass(int trafficClass) {
         try {
-            datagramChannel.socket.setTrafficClass(trafficClass);
+            ((EpollDatagramChannel) channel).socket.setTrafficClass(trafficClass);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -276,7 +274,7 @@ public EpollDatagramChannelConfig setTrafficClass(int trafficClass) {
     @Override
     public boolean isReuseAddress() {
         try {
-            return datagramChannel.socket.isReuseAddress();
+            return ((EpollDatagramChannel) channel).socket.isReuseAddress();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -285,7 +283,7 @@ public boolean isReuseAddress() {
     @Override
     public EpollDatagramChannelConfig setReuseAddress(boolean reuseAddress) {
         try {
-            datagramChannel.socket.setReuseAddress(reuseAddress);
+            ((EpollDatagramChannel) channel).socket.setReuseAddress(reuseAddress);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -295,7 +293,7 @@ public EpollDatagramChannelConfig setReuseAddress(boolean reuseAddress) {
     @Override
     public boolean isBroadcast() {
         try {
-            return datagramChannel.socket.isBroadcast();
+            return ((EpollDatagramChannel) channel).socket.isBroadcast();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -304,7 +302,7 @@ public boolean isBroadcast() {
     @Override
     public EpollDatagramChannelConfig setBroadcast(boolean broadcast) {
         try {
-            datagramChannel.socket.setBroadcast(broadcast);
+            ((EpollDatagramChannel) channel).socket.setBroadcast(broadcast);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -362,7 +360,7 @@ public EpollDatagramChannelConfig setEpollMode(EpollMode mode) {
      */
     public boolean isReusePort() {
         try {
-            return datagramChannel.socket.isReusePort();
+            return ((EpollDatagramChannel) channel).socket.isReusePort();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -377,7 +375,7 @@ public boolean isReusePort() {
      */
     public EpollDatagramChannelConfig setReusePort(boolean reusePort) {
         try {
-            datagramChannel.socket.setReusePort(reusePort);
+            ((EpollDatagramChannel) channel).socket.setReusePort(reusePort);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -390,7 +388,7 @@ public EpollDatagramChannelConfig setReusePort(boolean reusePort) {
      */
     public boolean isIpTransparent() {
         try {
-            return datagramChannel.socket.isIpTransparent();
+            return ((EpollDatagramChannel) channel).socket.isIpTransparent();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -402,7 +400,7 @@ public boolean isIpTransparent() {
      */
     public EpollDatagramChannelConfig setIpTransparent(boolean ipTransparent) {
         try {
-            datagramChannel.socket.setIpTransparent(ipTransparent);
+            ((EpollDatagramChannel) channel).socket.setIpTransparent(ipTransparent);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -415,7 +413,7 @@ public EpollDatagramChannelConfig setIpTransparent(boolean ipTransparent) {
      */
     public boolean isIpRecvOrigDestAddr() {
         try {
-            return datagramChannel.socket.isIpRecvOrigDestAddr();
+            return ((EpollDatagramChannel) channel).socket.isIpRecvOrigDestAddr();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -427,7 +425,7 @@ public boolean isIpRecvOrigDestAddr() {
      */
     public EpollDatagramChannelConfig setIpRecvOrigDestAddr(boolean ipTransparent) {
         try {
-            datagramChannel.socket.setIpRecvOrigDestAddr(ipTransparent);
+            ((EpollDatagramChannel) channel).socket.setIpRecvOrigDestAddr(ipTransparent);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerChannelConfig.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerChannelConfig.java
index 5d6394b1428..514b6c34cc4 100644
--- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerChannelConfig.java
+++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerChannelConfig.java
@@ -32,13 +32,11 @@
 import static io.netty.channel.ChannelOption.SO_REUSEADDR;
 
 public class EpollServerChannelConfig extends EpollChannelConfig implements ServerSocketChannelConfig {
-    protected final AbstractEpollChannel channel;
     private volatile int backlog = NetUtil.SOMAXCONN;
     private volatile int pendingFastOpenRequestsThreshold;
 
     EpollServerChannelConfig(AbstractEpollChannel channel) {
         super(channel);
-        this.channel = channel;
     }
 
     @Override
@@ -85,7 +83,7 @@ public <T> boolean setOption(ChannelOption<T> option, T value) {
 
     public boolean isReuseAddress() {
         try {
-            return channel.socket.isReuseAddress();
+            return ((AbstractEpollChannel) channel).socket.isReuseAddress();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -93,7 +91,7 @@ public boolean isReuseAddress() {
 
     public EpollServerChannelConfig setReuseAddress(boolean reuseAddress) {
         try {
-            channel.socket.setReuseAddress(reuseAddress);
+            ((AbstractEpollChannel) channel).socket.setReuseAddress(reuseAddress);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -102,7 +100,7 @@ public EpollServerChannelConfig setReuseAddress(boolean reuseAddress) {
 
     public int getReceiveBufferSize() {
         try {
-            return channel.socket.getReceiveBufferSize();
+            return ((AbstractEpollChannel) channel).socket.getReceiveBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -110,7 +108,7 @@ public int getReceiveBufferSize() {
 
     public EpollServerChannelConfig setReceiveBufferSize(int receiveBufferSize) {
         try {
-            channel.socket.setReceiveBufferSize(receiveBufferSize);
+            ((AbstractEpollChannel) channel).socket.setReceiveBufferSize(receiveBufferSize);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerSocketChannelConfig.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerSocketChannelConfig.java
index dfccb199c98..91861f0c137 100644
--- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerSocketChannelConfig.java
+++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollServerSocketChannelConfig.java
@@ -191,7 +191,7 @@ public EpollServerSocketChannelConfig setTcpMd5Sig(Map<InetAddress, byte[]> keys
      */
     public boolean isReusePort() {
         try {
-            return channel.socket.isReusePort();
+            return ((EpollServerSocketChannel) channel).socket.isReusePort();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -206,7 +206,7 @@ public boolean isReusePort() {
      */
     public EpollServerSocketChannelConfig setReusePort(boolean reusePort) {
         try {
-            channel.socket.setReusePort(reusePort);
+            ((EpollServerSocketChannel) channel).socket.setReusePort(reusePort);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -219,7 +219,7 @@ public EpollServerSocketChannelConfig setReusePort(boolean reusePort) {
      */
     public boolean isFreeBind() {
         try {
-            return channel.socket.isIpFreeBind();
+            return ((EpollServerSocketChannel) channel).socket.isIpFreeBind();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -231,7 +231,7 @@ public boolean isFreeBind() {
      */
     public EpollServerSocketChannelConfig setFreeBind(boolean freeBind) {
         try {
-            channel.socket.setIpFreeBind(freeBind);
+            ((EpollServerSocketChannel) channel).socket.setIpFreeBind(freeBind);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -244,7 +244,7 @@ public EpollServerSocketChannelConfig setFreeBind(boolean freeBind) {
      */
     public boolean isIpTransparent() {
         try {
-            return channel.socket.isIpTransparent();
+            return ((EpollServerSocketChannel) channel).socket.isIpTransparent();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -256,7 +256,7 @@ public boolean isIpTransparent() {
      */
     public EpollServerSocketChannelConfig setIpTransparent(boolean transparent) {
         try {
-            channel.socket.setIpTransparent(transparent);
+            ((EpollServerSocketChannel) channel).socket.setIpTransparent(transparent);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -268,7 +268,7 @@ public EpollServerSocketChannelConfig setIpTransparent(boolean transparent) {
      */
     public EpollServerSocketChannelConfig setTcpDeferAccept(int deferAccept) {
         try {
-            channel.socket.setTcpDeferAccept(deferAccept);
+            ((EpollServerSocketChannel) channel).socket.setTcpDeferAccept(deferAccept);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -280,7 +280,7 @@ public EpollServerSocketChannelConfig setTcpDeferAccept(int deferAccept) {
      */
     public int getTcpDeferAccept() {
         try {
-            return channel.socket.getTcpDeferAccept();
+            return ((EpollServerSocketChannel) channel).socket.getTcpDeferAccept();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannelConfig.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannelConfig.java
index d61bf19e27e..f3d04dd3f95 100644
--- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannelConfig.java
+++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollSocketChannelConfig.java
@@ -38,7 +38,6 @@
 import static io.netty.channel.ChannelOption.TCP_NODELAY;
 
 public final class EpollSocketChannelConfig extends EpollChannelConfig implements SocketChannelConfig {
-    private final EpollSocketChannel channel;
     private volatile boolean allowHalfClosure;
 
     /**
@@ -47,7 +46,6 @@ public final class EpollSocketChannelConfig extends EpollChannelConfig implement
     EpollSocketChannelConfig(EpollSocketChannel channel) {
         super(channel);
 
-        this.channel = channel;
         if (PlatformDependent.canEnableTcpNoDelayByDefault()) {
             setTcpNoDelay(true);
         }
@@ -179,7 +177,7 @@ public <T> boolean setOption(ChannelOption<T> option, T value) {
     @Override
     public int getReceiveBufferSize() {
         try {
-            return channel.socket.getReceiveBufferSize();
+            return ((EpollSocketChannel) channel).socket.getReceiveBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -188,7 +186,7 @@ public int getReceiveBufferSize() {
     @Override
     public int getSendBufferSize() {
         try {
-            return channel.socket.getSendBufferSize();
+            return ((EpollSocketChannel) channel).socket.getSendBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -197,7 +195,7 @@ public int getSendBufferSize() {
     @Override
     public int getSoLinger() {
         try {
-            return channel.socket.getSoLinger();
+            return ((EpollSocketChannel) channel).socket.getSoLinger();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -206,7 +204,7 @@ public int getSoLinger() {
     @Override
     public int getTrafficClass() {
         try {
-            return channel.socket.getTrafficClass();
+            return ((EpollSocketChannel) channel).socket.getTrafficClass();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -215,7 +213,7 @@ public int getTrafficClass() {
     @Override
     public boolean isKeepAlive() {
         try {
-            return channel.socket.isKeepAlive();
+            return ((EpollSocketChannel) channel).socket.isKeepAlive();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -224,7 +222,7 @@ public boolean isKeepAlive() {
     @Override
     public boolean isReuseAddress() {
         try {
-            return channel.socket.isReuseAddress();
+            return ((EpollSocketChannel) channel).socket.isReuseAddress();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -233,7 +231,7 @@ public boolean isReuseAddress() {
     @Override
     public boolean isTcpNoDelay() {
         try {
-            return channel.socket.isTcpNoDelay();
+            return ((EpollSocketChannel) channel).socket.isTcpNoDelay();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -244,7 +242,7 @@ public boolean isTcpNoDelay() {
      */
     public boolean isTcpCork() {
         try {
-            return channel.socket.isTcpCork();
+            return ((EpollSocketChannel) channel).socket.isTcpCork();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -255,7 +253,7 @@ public boolean isTcpCork() {
      */
     public int getSoBusyPoll() {
         try {
-            return channel.socket.getSoBusyPoll();
+            return ((EpollSocketChannel) channel).socket.getSoBusyPoll();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -267,7 +265,7 @@ public int getSoBusyPoll() {
      */
     public long getTcpNotSentLowAt() {
         try {
-            return channel.socket.getTcpNotSentLowAt();
+            return ((EpollSocketChannel) channel).socket.getTcpNotSentLowAt();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -278,7 +276,7 @@ public long getTcpNotSentLowAt() {
      */
     public int getTcpKeepIdle() {
         try {
-            return channel.socket.getTcpKeepIdle();
+            return ((EpollSocketChannel) channel).socket.getTcpKeepIdle();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -289,7 +287,7 @@ public int getTcpKeepIdle() {
      */
     public int getTcpKeepIntvl() {
         try {
-            return channel.socket.getTcpKeepIntvl();
+            return ((EpollSocketChannel) channel).socket.getTcpKeepIntvl();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -300,7 +298,7 @@ public int getTcpKeepIntvl() {
      */
     public int getTcpKeepCnt() {
         try {
-            return channel.socket.getTcpKeepCnt();
+            return ((EpollSocketChannel) channel).socket.getTcpKeepCnt();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -311,7 +309,7 @@ public int getTcpKeepCnt() {
      */
     public int getTcpUserTimeout() {
         try {
-            return channel.socket.getTcpUserTimeout();
+            return ((EpollSocketChannel) channel).socket.getTcpUserTimeout();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -320,7 +318,7 @@ public int getTcpUserTimeout() {
     @Override
     public EpollSocketChannelConfig setKeepAlive(boolean keepAlive) {
         try {
-            channel.socket.setKeepAlive(keepAlive);
+            ((EpollSocketChannel) channel).socket.setKeepAlive(keepAlive);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -336,7 +334,7 @@ public EpollSocketChannelConfig setPerformancePreferences(
     @Override
     public EpollSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
         try {
-            channel.socket.setReceiveBufferSize(receiveBufferSize);
+            ((EpollSocketChannel) channel).socket.setReceiveBufferSize(receiveBufferSize);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -346,7 +344,7 @@ public EpollSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
     @Override
     public EpollSocketChannelConfig setReuseAddress(boolean reuseAddress) {
         try {
-            channel.socket.setReuseAddress(reuseAddress);
+            ((EpollSocketChannel) channel).socket.setReuseAddress(reuseAddress);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -356,7 +354,7 @@ public EpollSocketChannelConfig setReuseAddress(boolean reuseAddress) {
     @Override
     public EpollSocketChannelConfig setSendBufferSize(int sendBufferSize) {
         try {
-            channel.socket.setSendBufferSize(sendBufferSize);
+            ((EpollSocketChannel) channel).socket.setSendBufferSize(sendBufferSize);
             calculateMaxBytesPerGatheringWrite();
             return this;
         } catch (IOException e) {
@@ -367,7 +365,7 @@ public EpollSocketChannelConfig setSendBufferSize(int sendBufferSize) {
     @Override
     public EpollSocketChannelConfig setSoLinger(int soLinger) {
         try {
-            channel.socket.setSoLinger(soLinger);
+            ((EpollSocketChannel) channel).socket.setSoLinger(soLinger);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -377,7 +375,7 @@ public EpollSocketChannelConfig setSoLinger(int soLinger) {
     @Override
     public EpollSocketChannelConfig setTcpNoDelay(boolean tcpNoDelay) {
         try {
-            channel.socket.setTcpNoDelay(tcpNoDelay);
+            ((EpollSocketChannel) channel).socket.setTcpNoDelay(tcpNoDelay);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -389,7 +387,7 @@ public EpollSocketChannelConfig setTcpNoDelay(boolean tcpNoDelay) {
      */
     public EpollSocketChannelConfig setTcpCork(boolean tcpCork) {
         try {
-            channel.socket.setTcpCork(tcpCork);
+            ((EpollSocketChannel) channel).socket.setTcpCork(tcpCork);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -401,7 +399,7 @@ public EpollSocketChannelConfig setTcpCork(boolean tcpCork) {
      */
     public EpollSocketChannelConfig setSoBusyPoll(int loopMicros) {
         try {
-            channel.socket.setSoBusyPoll(loopMicros);
+            ((EpollSocketChannel) channel).socket.setSoBusyPoll(loopMicros);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -414,7 +412,7 @@ public EpollSocketChannelConfig setSoBusyPoll(int loopMicros) {
      */
     public EpollSocketChannelConfig setTcpNotSentLowAt(long tcpNotSentLowAt) {
         try {
-            channel.socket.setTcpNotSentLowAt(tcpNotSentLowAt);
+            ((EpollSocketChannel) channel).socket.setTcpNotSentLowAt(tcpNotSentLowAt);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -424,7 +422,7 @@ public EpollSocketChannelConfig setTcpNotSentLowAt(long tcpNotSentLowAt) {
     @Override
     public EpollSocketChannelConfig setTrafficClass(int trafficClass) {
         try {
-            channel.socket.setTrafficClass(trafficClass);
+            ((EpollSocketChannel) channel).socket.setTrafficClass(trafficClass);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -436,7 +434,7 @@ public EpollSocketChannelConfig setTrafficClass(int trafficClass) {
      */
     public EpollSocketChannelConfig setTcpKeepIdle(int seconds) {
         try {
-            channel.socket.setTcpKeepIdle(seconds);
+            ((EpollSocketChannel) channel).socket.setTcpKeepIdle(seconds);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -448,7 +446,7 @@ public EpollSocketChannelConfig setTcpKeepIdle(int seconds) {
      */
     public EpollSocketChannelConfig setTcpKeepIntvl(int seconds) {
         try {
-            channel.socket.setTcpKeepIntvl(seconds);
+            ((EpollSocketChannel) channel).socket.setTcpKeepIntvl(seconds);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -468,7 +466,7 @@ public EpollSocketChannelConfig setTcpKeepCntl(int probes) {
      */
     public EpollSocketChannelConfig setTcpKeepCnt(int probes) {
         try {
-            channel.socket.setTcpKeepCnt(probes);
+            ((EpollSocketChannel) channel).socket.setTcpKeepCnt(probes);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -480,7 +478,7 @@ public EpollSocketChannelConfig setTcpKeepCnt(int probes) {
      */
     public EpollSocketChannelConfig setTcpUserTimeout(int milliseconds) {
         try {
-            channel.socket.setTcpUserTimeout(milliseconds);
+            ((EpollSocketChannel) channel).socket.setTcpUserTimeout(milliseconds);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -493,7 +491,7 @@ public EpollSocketChannelConfig setTcpUserTimeout(int milliseconds) {
      */
     public boolean isIpTransparent() {
         try {
-            return channel.socket.isIpTransparent();
+            return ((EpollSocketChannel) channel).socket.isIpTransparent();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -505,7 +503,7 @@ public boolean isIpTransparent() {
      */
     public EpollSocketChannelConfig setIpTransparent(boolean transparent) {
         try {
-            channel.socket.setIpTransparent(transparent);
+            ((EpollSocketChannel) channel).socket.setIpTransparent(transparent);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -519,7 +517,7 @@ public EpollSocketChannelConfig setIpTransparent(boolean transparent) {
      */
     public EpollSocketChannelConfig setTcpMd5Sig(Map<InetAddress, byte[]> keys) {
         try {
-            channel.setTcpMd5Sig(keys);
+            ((EpollSocketChannel) channel).setTcpMd5Sig(keys);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -532,7 +530,7 @@ public EpollSocketChannelConfig setTcpMd5Sig(Map<InetAddress, byte[]> keys) {
      */
     public EpollSocketChannelConfig setTcpQuickAck(boolean quickAck) {
         try {
-            channel.socket.setTcpQuickAck(quickAck);
+            ((EpollSocketChannel) channel).socket.setTcpQuickAck(quickAck);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -545,7 +543,7 @@ public EpollSocketChannelConfig setTcpQuickAck(boolean quickAck) {
      */
     public boolean isTcpQuickAck() {
         try {
-            return channel.socket.isTcpQuickAck();
+            return ((EpollSocketChannel) channel).socket.isTcpQuickAck();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -559,7 +557,7 @@ public boolean isTcpQuickAck() {
      */
     public EpollSocketChannelConfig setTcpFastOpenConnect(boolean fastOpenConnect) {
         try {
-            channel.socket.setTcpFastOpenConnect(fastOpenConnect);
+            ((EpollSocketChannel) channel).socket.setTcpFastOpenConnect(fastOpenConnect);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -571,7 +569,7 @@ public EpollSocketChannelConfig setTcpFastOpenConnect(boolean fastOpenConnect) {
      */
     public boolean isTcpFastOpenConnect() {
         try {
-            return channel.socket.isTcpFastOpenConnect();
+            return ((EpollSocketChannel) channel).socket.isTcpFastOpenConnect();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
diff --git a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueChannelConfig.java b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueChannelConfig.java
index 878663c5e74..c2b1debe983 100644
--- a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueChannelConfig.java
+++ b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueChannelConfig.java
@@ -31,13 +31,11 @@
 
 @UnstableApi
 public class KQueueChannelConfig extends DefaultChannelConfig {
-    final AbstractKQueueChannel channel;
     private volatile boolean transportProvidesGuess;
     private volatile long maxBytesPerGatheringWrite = SSIZE_MAX;
 
     KQueueChannelConfig(AbstractKQueueChannel channel) {
         super(channel);
-        this.channel = channel;
     }
 
     @Override
@@ -154,7 +152,7 @@ public KQueueChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimato
 
     @Override
     protected final void autoReadCleared() {
-        channel.clearReadFilter();
+        ((AbstractKQueueChannel) channel).clearReadFilter();
     }
 
     final void setMaxBytesPerGatheringWrite(long maxBytesPerGatheringWrite) {
diff --git a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannelConfig.java b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannelConfig.java
index c64417485b9..478d5544d16 100644
--- a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannelConfig.java
+++ b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannelConfig.java
@@ -45,12 +45,10 @@
 @UnstableApi
 public final class KQueueDatagramChannelConfig extends KQueueChannelConfig implements DatagramChannelConfig {
     private static final RecvByteBufAllocator DEFAULT_RCVBUF_ALLOCATOR = new FixedRecvByteBufAllocator(2048);
-    private final KQueueDatagramChannel datagramChannel;
     private boolean activeOnOpen;
 
     KQueueDatagramChannelConfig(KQueueDatagramChannel channel) {
         super(channel);
-        this.datagramChannel = channel;
         setRecvByteBufAllocator(DEFAULT_RCVBUF_ALLOCATOR);
     }
 
@@ -153,7 +151,7 @@ boolean getActiveOnOpen() {
      */
     public boolean isReusePort() {
         try {
-            return datagramChannel.socket.isReusePort();
+            return ((KQueueDatagramChannel) channel).socket.isReusePort();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -168,7 +166,7 @@ public boolean isReusePort() {
      */
     public KQueueDatagramChannelConfig setReusePort(boolean reusePort) {
         try {
-            datagramChannel.socket.setReusePort(reusePort);
+            ((KQueueDatagramChannel) channel).socket.setReusePort(reusePort);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -253,7 +251,7 @@ public KQueueDatagramChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead)
     @Override
     public int getSendBufferSize() {
         try {
-            return datagramChannel.socket.getSendBufferSize();
+            return ((KQueueDatagramChannel) channel).socket.getSendBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -262,7 +260,7 @@ public int getSendBufferSize() {
     @Override
     public KQueueDatagramChannelConfig setSendBufferSize(int sendBufferSize) {
         try {
-            datagramChannel.socket.setSendBufferSize(sendBufferSize);
+            ((KQueueDatagramChannel) channel).socket.setSendBufferSize(sendBufferSize);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -272,7 +270,7 @@ public KQueueDatagramChannelConfig setSendBufferSize(int sendBufferSize) {
     @Override
     public int getReceiveBufferSize() {
         try {
-            return datagramChannel.socket.getReceiveBufferSize();
+            return ((KQueueDatagramChannel) channel).socket.getReceiveBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -281,7 +279,7 @@ public int getReceiveBufferSize() {
     @Override
     public KQueueDatagramChannelConfig setReceiveBufferSize(int receiveBufferSize) {
         try {
-            datagramChannel.socket.setReceiveBufferSize(receiveBufferSize);
+            ((KQueueDatagramChannel) channel).socket.setReceiveBufferSize(receiveBufferSize);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -291,7 +289,7 @@ public KQueueDatagramChannelConfig setReceiveBufferSize(int receiveBufferSize) {
     @Override
     public int getTrafficClass() {
         try {
-            return datagramChannel.socket.getTrafficClass();
+            return ((KQueueDatagramChannel) channel).socket.getTrafficClass();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -300,7 +298,7 @@ public int getTrafficClass() {
     @Override
     public KQueueDatagramChannelConfig setTrafficClass(int trafficClass) {
         try {
-            datagramChannel.socket.setTrafficClass(trafficClass);
+            ((KQueueDatagramChannel) channel).socket.setTrafficClass(trafficClass);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -310,7 +308,7 @@ public KQueueDatagramChannelConfig setTrafficClass(int trafficClass) {
     @Override
     public boolean isReuseAddress() {
         try {
-            return datagramChannel.socket.isReuseAddress();
+            return ((KQueueDatagramChannel) channel).socket.isReuseAddress();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -319,7 +317,7 @@ public boolean isReuseAddress() {
     @Override
     public KQueueDatagramChannelConfig setReuseAddress(boolean reuseAddress) {
         try {
-            datagramChannel.socket.setReuseAddress(reuseAddress);
+            ((KQueueDatagramChannel) channel).socket.setReuseAddress(reuseAddress);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -329,7 +327,7 @@ public KQueueDatagramChannelConfig setReuseAddress(boolean reuseAddress) {
     @Override
     public boolean isBroadcast() {
         try {
-            return datagramChannel.socket.isBroadcast();
+            return ((KQueueDatagramChannel) channel).socket.isBroadcast();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -338,7 +336,7 @@ public boolean isBroadcast() {
     @Override
     public KQueueDatagramChannelConfig setBroadcast(boolean broadcast) {
         try {
-            datagramChannel.socket.setBroadcast(broadcast);
+            ((KQueueDatagramChannel) channel).socket.setBroadcast(broadcast);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
diff --git a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueServerChannelConfig.java b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueServerChannelConfig.java
index 7f878dc2577..09291f58dbf 100644
--- a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueServerChannelConfig.java
+++ b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueServerChannelConfig.java
@@ -34,12 +34,10 @@
 
 @UnstableApi
 public class KQueueServerChannelConfig extends KQueueChannelConfig implements ServerSocketChannelConfig {
-    protected final AbstractKQueueChannel channel;
     private volatile int backlog = NetUtil.SOMAXCONN;
 
     KQueueServerChannelConfig(AbstractKQueueChannel channel) {
         super(channel);
-        this.channel = channel;
     }
 
     @Override
@@ -81,7 +79,7 @@ public <T> boolean setOption(ChannelOption<T> option, T value) {
 
     public boolean isReuseAddress() {
         try {
-            return channel.socket.isReuseAddress();
+            return ((AbstractKQueueChannel) channel).socket.isReuseAddress();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -89,7 +87,7 @@ public boolean isReuseAddress() {
 
     public KQueueServerChannelConfig setReuseAddress(boolean reuseAddress) {
         try {
-            channel.socket.setReuseAddress(reuseAddress);
+            ((AbstractKQueueChannel) channel).socket.setReuseAddress(reuseAddress);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -98,7 +96,7 @@ public KQueueServerChannelConfig setReuseAddress(boolean reuseAddress) {
 
     public int getReceiveBufferSize() {
         try {
-            return channel.socket.getReceiveBufferSize();
+            return ((AbstractKQueueChannel) channel).socket.getReceiveBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -106,7 +104,7 @@ public int getReceiveBufferSize() {
 
     public KQueueServerChannelConfig setReceiveBufferSize(int receiveBufferSize) {
         try {
-            channel.socket.setReceiveBufferSize(receiveBufferSize);
+            ((AbstractKQueueChannel) channel).socket.setReceiveBufferSize(receiveBufferSize);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
diff --git a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueServerSocketChannelConfig.java b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueServerSocketChannelConfig.java
index dce3e6e71b8..a743e039de6 100644
--- a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueServerSocketChannelConfig.java
+++ b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueServerSocketChannelConfig.java
@@ -75,7 +75,7 @@ public <T> boolean setOption(ChannelOption<T> option, T value) {
 
     public KQueueServerSocketChannelConfig setReusePort(boolean reusePort) {
         try {
-            channel.socket.setReusePort(reusePort);
+            ((KQueueServerSocketChannel) channel).socket.setReusePort(reusePort);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -84,7 +84,7 @@ public KQueueServerSocketChannelConfig setReusePort(boolean reusePort) {
 
     public boolean isReusePort() {
         try {
-            return channel.socket.isReusePort();
+            return ((KQueueServerSocketChannel) channel).socket.isReusePort();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -92,7 +92,7 @@ public boolean isReusePort() {
 
     public KQueueServerSocketChannelConfig setAcceptFilter(AcceptFilter acceptFilter) {
         try {
-            channel.socket.setAcceptFilter(acceptFilter);
+            ((KQueueServerSocketChannel) channel).socket.setAcceptFilter(acceptFilter);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -101,7 +101,7 @@ public KQueueServerSocketChannelConfig setAcceptFilter(AcceptFilter acceptFilter
 
     public AcceptFilter getAcceptFilter() {
         try {
-            return channel.socket.getAcceptFilter();
+            return ((KQueueServerSocketChannel) channel).socket.getAcceptFilter();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
diff --git a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueSocketChannelConfig.java b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueSocketChannelConfig.java
index 8662e55c7b9..b5c718b9113 100644
--- a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueSocketChannelConfig.java
+++ b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueSocketChannelConfig.java
@@ -41,12 +41,10 @@
 
 @UnstableApi
 public final class KQueueSocketChannelConfig extends KQueueChannelConfig implements SocketChannelConfig {
-    private final KQueueSocketChannel channel;
     private volatile boolean allowHalfClosure;
 
     KQueueSocketChannelConfig(KQueueSocketChannel channel) {
         super(channel);
-        this.channel = channel;
         if (PlatformDependent.canEnableTcpNoDelayByDefault()) {
             setTcpNoDelay(true);
         }
@@ -131,7 +129,7 @@ public <T> boolean setOption(ChannelOption<T> option, T value) {
     @Override
     public int getReceiveBufferSize() {
         try {
-            return channel.socket.getReceiveBufferSize();
+            return ((KQueueSocketChannel) channel).socket.getReceiveBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -140,7 +138,7 @@ public int getReceiveBufferSize() {
     @Override
     public int getSendBufferSize() {
         try {
-            return channel.socket.getSendBufferSize();
+            return ((KQueueSocketChannel) channel).socket.getSendBufferSize();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -149,7 +147,7 @@ public int getSendBufferSize() {
     @Override
     public int getSoLinger() {
         try {
-            return channel.socket.getSoLinger();
+            return ((KQueueSocketChannel) channel).socket.getSoLinger();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -158,7 +156,7 @@ public int getSoLinger() {
     @Override
     public int getTrafficClass() {
         try {
-            return channel.socket.getTrafficClass();
+            return ((KQueueSocketChannel) channel).socket.getTrafficClass();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -167,7 +165,7 @@ public int getTrafficClass() {
     @Override
     public boolean isKeepAlive() {
         try {
-            return channel.socket.isKeepAlive();
+            return ((KQueueSocketChannel) channel).socket.isKeepAlive();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -176,7 +174,7 @@ public boolean isKeepAlive() {
     @Override
     public boolean isReuseAddress() {
         try {
-            return channel.socket.isReuseAddress();
+            return ((KQueueSocketChannel) channel).socket.isReuseAddress();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -185,7 +183,7 @@ public boolean isReuseAddress() {
     @Override
     public boolean isTcpNoDelay() {
         try {
-            return channel.socket.isTcpNoDelay();
+            return ((KQueueSocketChannel) channel).socket.isTcpNoDelay();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -193,7 +191,7 @@ public boolean isTcpNoDelay() {
 
     public int getSndLowAt() {
         try {
-            return channel.socket.getSndLowAt();
+            return ((KQueueSocketChannel) channel).socket.getSndLowAt();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -201,7 +199,7 @@ public int getSndLowAt() {
 
     public void setSndLowAt(int sndLowAt)  {
         try {
-            channel.socket.setSndLowAt(sndLowAt);
+            ((KQueueSocketChannel) channel).socket.setSndLowAt(sndLowAt);
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -209,7 +207,7 @@ public void setSndLowAt(int sndLowAt)  {
 
     public boolean isTcpNoPush() {
         try {
-            return channel.socket.isTcpNoPush();
+            return ((KQueueSocketChannel) channel).socket.isTcpNoPush();
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -217,7 +215,7 @@ public boolean isTcpNoPush() {
 
     public void setTcpNoPush(boolean tcpNoPush)  {
         try {
-            channel.socket.setTcpNoPush(tcpNoPush);
+            ((KQueueSocketChannel) channel).socket.setTcpNoPush(tcpNoPush);
         } catch (IOException e) {
             throw new ChannelException(e);
         }
@@ -226,7 +224,7 @@ public void setTcpNoPush(boolean tcpNoPush)  {
     @Override
     public KQueueSocketChannelConfig setKeepAlive(boolean keepAlive) {
         try {
-            channel.socket.setKeepAlive(keepAlive);
+            ((KQueueSocketChannel) channel).socket.setKeepAlive(keepAlive);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -236,7 +234,7 @@ public KQueueSocketChannelConfig setKeepAlive(boolean keepAlive) {
     @Override
     public KQueueSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
         try {
-            channel.socket.setReceiveBufferSize(receiveBufferSize);
+            ((KQueueSocketChannel) channel).socket.setReceiveBufferSize(receiveBufferSize);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -246,7 +244,7 @@ public KQueueSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
     @Override
     public KQueueSocketChannelConfig setReuseAddress(boolean reuseAddress) {
         try {
-            channel.socket.setReuseAddress(reuseAddress);
+            ((KQueueSocketChannel) channel).socket.setReuseAddress(reuseAddress);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -256,7 +254,7 @@ public KQueueSocketChannelConfig setReuseAddress(boolean reuseAddress) {
     @Override
     public KQueueSocketChannelConfig setSendBufferSize(int sendBufferSize) {
         try {
-            channel.socket.setSendBufferSize(sendBufferSize);
+            ((KQueueSocketChannel) channel).socket.setSendBufferSize(sendBufferSize);
             calculateMaxBytesPerGatheringWrite();
             return this;
         } catch (IOException e) {
@@ -267,7 +265,7 @@ public KQueueSocketChannelConfig setSendBufferSize(int sendBufferSize) {
     @Override
     public KQueueSocketChannelConfig setSoLinger(int soLinger) {
         try {
-            channel.socket.setSoLinger(soLinger);
+            ((KQueueSocketChannel) channel).socket.setSoLinger(soLinger);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -277,7 +275,7 @@ public KQueueSocketChannelConfig setSoLinger(int soLinger) {
     @Override
     public KQueueSocketChannelConfig setTcpNoDelay(boolean tcpNoDelay) {
         try {
-            channel.socket.setTcpNoDelay(tcpNoDelay);
+            ((KQueueSocketChannel) channel).socket.setTcpNoDelay(tcpNoDelay);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);
@@ -287,7 +285,7 @@ public KQueueSocketChannelConfig setTcpNoDelay(boolean tcpNoDelay) {
     @Override
     public KQueueSocketChannelConfig setTrafficClass(int trafficClass) {
         try {
-            channel.socket.setTrafficClass(trafficClass);
+            ((KQueueSocketChannel) channel).socket.setTrafficClass(trafficClass);
             return this;
         } catch (IOException e) {
             throw new ChannelException(e);


Test patch: