Repository: netty/netty
Issue: ClassCastException while setting Sctp Inbound/Outbound streams in ChannelConfig in CR10-SNAPSHOT

In Netty CR-10 SNAPSHOT

``` Java
    final int MAX_INBOUND_STREAMS = 10;
    final int MAX_OUTBOUND_STREAMS = 10;
    List<Integer> streamConfig = new ArrayList<Integer>(2);

    streamConfig.add(MAX_INBOUND_STREAMS);
    streamConfig.add(MAX_OUTBOUND_STREAMS);


    Bootstrap cb = new Bootstrap();

    cb.group(new NioEventLoopGroup()).
    handler(new ChannelInitializer() {
        @Override
         public void initChannel(Channel ch) throws Exception {
             ch.pipeline().addLast(clientMeter);
         }
    }).
    option(SctpChannelOption.SCTP_NODELAY, true).
    option(SctpChannelOption.SCTP_INIT_MAXSTREAMS, streamConfig).
    option(SctpChannelOption.SO_RCVBUF, 1024 * 1024 * 1024).
    option(SctpChannelOption.SO_SNDBUF, 1024 * 1024 * 1024);
```

Jul 09, 2013 11:44:46 PM io.netty.bootstrap.Bootstrap init
WARNING: Failed to set a channel option: [id: 0x2a71a639]
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.sun.nio.sctp.SctpStandardSocketOptions$InitMaxStreams
    at io.netty.channel.sctp.DefaultSctpChannelConfig.setOption(DefaultSctpChannelConfig.java:90)
    at io.netty.bootstrap.Bootstrap.init(Bootstrap.java:187)
    at io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:280)
    at io.netty.bootstrap.Bootstrap.doConnect(Bootstrap.java:133)
    at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:89)


Issue comments:
@jestan after more thoughts I wonder why you not use InitMaxStreams.create(...) directly... Can you provide more info ?

@jestan reverted this fix again as after more review I think the current impl is correct.

@normanmaurer I think there is a problem. SctpChannelOption validates for List<Integer>. Thats why I have fixed the ClassCastException. Can we change SctpChannelOption back to InitMaxStream?

I can not remember why InitMaxStream changed to List https://github.com/netty/netty/blob/master/transport-sctp/src/main/java/io/netty/channel/sctp/SctpChannelOption.java#L33

@jestan yeah.. I will take care :)

@jestan done! Thanks for reporting


Pull request review comments:

Patch that resolved the issue:
diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java
index 8e7c2ffb222..37ec6ee79fc 100644
--- a/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java
+++ b/transport-sctp/src/main/java/io/netty/channel/sctp/DefaultSctpChannelConfig.java
@@ -26,6 +26,7 @@
 import io.netty.util.internal.PlatformDependent;
 
 import java.io.IOException;
+import java.util.List;
 import java.util.Map;
 
 import static io.netty.channel.sctp.SctpChannelOption.*;
@@ -87,7 +88,8 @@ public <T> boolean setOption(ChannelOption<T> option, T value) {
         } else if (option == SCTP_NODELAY) {
             setSctpNoDelay((Boolean) value);
         } else if (option == SCTP_INIT_MAXSTREAMS) {
-            setInitMaxStreams((SctpStandardSocketOptions.InitMaxStreams) value);
+            List<Integer> streams = (List<Integer>) value;
+            setInitMaxStreams(SctpStandardSocketOptions.InitMaxStreams.create(streams.get(0), streams.get(1)));
         } else {
             return super.setOption(option, value);
         }


Test patch: