title: Can a Netty NIO channel be writable but not connected?
body: <p>I have a handler that receives an <code>channelInterestChanged</code> callback then tests the channel's <code>isWritable()</code> method in that callback and fires a <code>writeRequest</code> event downstream if it is.</p>
  
  <p>Sometimes if this occurs right as the channel is being opened the channel throws an exception event with the cause as <code>java.nio.channels.NotYetConnectedException</code>.</p>
  
  <p>Should <code>isWritable() == true</code> assume <code>isConnected() == true</code> or did I screw this up?</p>
  
  <p>Example:</p>
  
  <pre><code>@Override
  public void channelInterestChanged(ChannelHandlerContext ctx,
          ChannelStateEvent e) throws Exception {
      MyMessage msg;
      while(ctx.getChannel().isWritable()){
          msg = queue.poll();
          Channels.write(ctx, Channels.succeededFuture(ctx.getChannel()), msg);
      }
  }
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>java.nio.channels.NotYetConnectedException
  at org.jboss.netty.channel.socket.nio.AbstractNioWorker.cleanUpWriteBuffer(AbstractNioWorker.java:696)
      at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromUserCode(AbstractNioWorker.java:421)
      at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink.eventSunk(NioClientSocketPipelineSink.java:116)
      at org.jboss.netty.channel.Channels.write(Channels.java:733)
      at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:65)
      at org.jboss.netty.channel.Channels.write(Channels.java:733)
      at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:65)
      at org.jboss.netty.channel.Channels.write(Channels.java:733)
      at org.jboss.netty.channel.Channels.write(Channels.java:694) &lt;--- this call is guarded by `isWritable()`
      at foo.bar.MyHandler.channelInterestChanged(MyHandler.java:44) &lt;--- My handler
      at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:61)
      at org.jboss.netty.channel.Channels.fireChannelInterestChanged(Channels.java:361)
      at org.jboss.netty.channel.Channels$3.run(Channels.java:349)
      at org.jboss.netty.channel.socket.ChannelRunnableWrapper.run(ChannelRunnableWrapper.java:41)
      at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processEventQueue(AbstractNioWorker.java:373)
      at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:254)
      at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>