Program: 113782
Project: 113782
Buggy source:
private void writeConnection(SelectionKey key){
  final ServerConnection con=(ServerConnection)key.attachment();
  final ChannelIO channel=con.getChannel();
  try {
    while (true) {
      ONCRPCRequest send=con.getSendRequest();
      if (send == null) {
synchronized (con) {
          send=con.getSendQueue().poll();
          if (send == null) {
            key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
            break;
          }
          con.setSendRequest(send);
        }
        final ByteBuffer fragHdrBuffer=con.getRequestFragHdr();
        final int fragmentSize=send.getRequestSize();
        final int fragHdrInt=ONCRPCRecordFragmentHeader.getFragmentHeader(fragmentSize,true);
        fragHdrBuffer.position(0);
        fragHdrBuffer.putInt(fragHdrInt);
        fragHdrBuffer.position(0);
      }
      final ByteBuffer fragHdrBuffer=con.getRequestFragHdr();
      if (fragHdrBuffer.hasRemaining()) {
        final int numBytesWritten=RPCNIOSocketServer.writeData(key,channel,fragHdrBuffer);
        if (numBytesWritten == -1) {
          closeConnection(key,new IOException("String_Node_Str"));
          return;
        }
        if (fragHdrBuffer.hasRemaining()) {
          break;
        }
      }
 else {
        final ReusableBuffer buf=send.getCurrentRequestBuffer();
        final int numBytesWritten=RPCNIOSocketServer.writeData(key,channel,buf.getBuffer());
        if (numBytesWritten == -1) {
          closeConnection(key,new IOException("String_Node_Str"));
          return;
        }
        if (buf.hasRemaining()) {
          break;
        }
 else {
          if (!send.isLastRequestBuffer()) {
            send.nextRequestBuffer();
          }
          con.addRequest(send.getXID(),send);
          con.setSendRequest(null);
        }
      }
    }
  }
 catch (  IOException ex) {
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,this,ex);
    }
    closeConnection(key,new IOException("String_Node_Str",ex));
  }
}

Fixed version (ground truth):
private void writeConnection(SelectionKey key){
  final ServerConnection con=(ServerConnection)key.attachment();
  final ChannelIO channel=con.getChannel();
  try {
    while (true) {
      ONCRPCRequest send=con.getSendRequest();
      if (send == null) {
synchronized (con) {
          send=con.getSendQueue().poll();
          if (send == null) {
            key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
            break;
          }
          con.setSendRequest(send);
        }
        final ByteBuffer fragHdrBuffer=con.getRequestFragHdr();
        final int fragmentSize=send.getRequestSize();
        final int fragHdrInt=ONCRPCRecordFragmentHeader.getFragmentHeader(fragmentSize,true);
        fragHdrBuffer.position(0);
        fragHdrBuffer.putInt(fragHdrInt);
        fragHdrBuffer.position(0);
      }
      final ByteBuffer fragHdrBuffer=con.getRequestFragHdr();
      if (fragHdrBuffer.hasRemaining()) {
        final int numBytesWritten=RPCNIOSocketServer.writeData(key,channel,fragHdrBuffer);
        if (numBytesWritten == -1) {
          closeConnection(key,new IOException("String_Node_Str"));
          return;
        }
        if (fragHdrBuffer.hasRemaining()) {
          break;
        }
      }
 else {
        final ReusableBuffer buf=send.getCurrentRequestBuffer();
        final int numBytesWritten=RPCNIOSocketServer.writeData(key,channel,buf.getBuffer());
        if (numBytesWritten == -1) {
          closeConnection(key,new IOException("String_Node_Str"));
          return;
        }
        if (buf.hasRemaining()) {
          break;
        }
 else {
          if (!send.isLastRequestBuffer()) {
            send.nextRequestBuffer();
          }
 else {
            con.addRequest(send.getXID(),send);
            con.setSendRequest(null);
            Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + con.getEndpoint());
          }
        }
      }
    }
  }
 catch (  IOException ex) {
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,this,ex);
    }
    closeConnection(key,new IOException("String_Node_Str",ex));
  }
}