Program: 113818
Project: 113818
Buggy source:
/** 
 * read data from a readable connection
 * @param key a readable key
 */
private void readConnection(SelectionKey key){
  final ClientConnection con=(ClientConnection)key.attachment();
  final ChannelIO channel=con.getChannel();
  try {
    if (con.getOpenRequests().get() > MAX_CLIENT_QUEUE) {
      key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);
      Logging.logMessage(Logging.LEVEL_WARN,this,"String_Node_Str" + con.getChannel().socket().getRemoteSocketAddress());
      return;
    }
    while (true) {
      final ByteBuffer fragmentHeader=con.getReceiveFragHdr();
      if (fragmentHeader.hasRemaining()) {
        final int numBytesRead=readData(key,channel,fragmentHeader);
        if (numBytesRead == -1) {
          closeConnection(key);
          return;
        }
        if (fragmentHeader.hasRemaining()) {
          break;
        }
 else {
          fragmentHeader.position(0);
          final int fragmentHeaderInt=fragmentHeader.getInt();
          final int fragmentSize=ONCRPCRecordFragmentHeader.getFragmentLength(fragmentHeaderInt);
          final boolean lastFragment=ONCRPCRecordFragmentHeader.isLastFragment(fragmentHeaderInt);
          if ((fragmentSize <= 0) || (fragmentSize >= MAX_FRAGMENT_SIZE)) {
            if (Logging.isDebug()) {
              Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + fragmentSize + "String_Node_Str");
            }
            closeConnection(key);
            break;
          }
          final ReusableBuffer fragment=BufferPool.allocate(fragmentSize);
          ONCRPCRecord rq=con.getReceive();
          if (rq == null) {
            rq=new ONCRPCRecord(this,con);
            con.setReceive(rq);
          }
          rq.addNewRequestFragment(fragment);
          rq.setAllFragmentsReceived(lastFragment);
        }
      }
 else {
        final ONCRPCRecord rq=con.getReceive();
        final ReusableBuffer fragment=rq.getLastRequestFragment();
        final int numBytesRead=readData(key,channel,fragment.getBuffer());
        if (numBytesRead == -1) {
          closeConnection(key);
          return;
        }
        if (fragment.hasRemaining()) {
          break;
        }
 else {
          fragmentHeader.position(0);
          if (rq.isAllFragmentsReceived()) {
            con.setReceive(null);
            if (Logging.tracingEnabled()) {
              Logging.logMessage(Logging.LEVEL_DEBUG,this,rq.toString());
            }
            con.getOpenRequests().incrementAndGet();
            receiveRequest(key,rq);
          }
        }
      }
    }
  }
 catch (  ClosedByInterruptException ex) {
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + con.getChannel().socket().getRemoteSocketAddress() + "String_Node_Str");
    }
    closeConnection(key);
  }
catch (  IOException ex) {
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,this,ex);
    }
    closeConnection(key);
  }
}

Fixed version (ground truth):
/** 
 * read data from a readable connection
 * @param key a readable key
 */
private void readConnection(SelectionKey key){
  final ClientConnection con=(ClientConnection)key.attachment();
  final ChannelIO channel=con.getChannel();
  try {
    if (con.getOpenRequests().get() > MAX_CLIENT_QUEUE) {
      key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);
      Logging.logMessage(Logging.LEVEL_WARN,this,"String_Node_Str" + con.getChannel().socket().getRemoteSocketAddress());
      return;
    }
    while (true) {
      final ByteBuffer fragmentHeader=con.getReceiveFragHdr();
      if (fragmentHeader.hasRemaining()) {
        final int numBytesRead=readData(key,channel,fragmentHeader);
        if (numBytesRead == -1) {
          closeConnection(key);
          return;
        }
        if (fragmentHeader.hasRemaining()) {
          break;
        }
 else {
          fragmentHeader.position(0);
          final int fragmentHeaderInt=fragmentHeader.getInt();
          final int fragmentSize=ONCRPCRecordFragmentHeader.getFragmentLength(fragmentHeaderInt);
          final boolean lastFragment=ONCRPCRecordFragmentHeader.isLastFragment(fragmentHeaderInt);
          if ((fragmentSize <= 0) || (fragmentSize >= MAX_FRAGMENT_SIZE)) {
            if (Logging.isDebug()) {
              Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + fragmentSize + "String_Node_Str");
            }
            closeConnection(key);
            break;
          }
          final ReusableBuffer fragment=BufferPool.allocate(fragmentSize);
          ONCRPCRecord rq=con.getReceive();
          if (rq == null) {
            rq=new ONCRPCRecord(this,con);
            con.setReceive(rq);
          }
          rq.addNewRequestFragment(fragment);
          rq.setAllFragmentsReceived(lastFragment);
        }
      }
 else {
        final ONCRPCRecord rq=con.getReceive();
        final ReusableBuffer fragment=rq.getLastRequestFragment();
        final int numBytesRead=readData(key,channel,fragment.getBuffer());
        if (numBytesRead == -1) {
          closeConnection(key);
          return;
        }
        if (fragment.hasRemaining()) {
          break;
        }
 else {
          fragmentHeader.position(0);
          if (rq.isAllFragmentsReceived()) {
            con.setReceive(null);
            if (Logging.tracingEnabled()) {
              Logging.logMessage(Logging.LEVEL_DEBUG,this,rq.toString());
            }
            con.getOpenRequests().incrementAndGet();
            Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str");
            receiveRequest(key,rq);
          }
        }
      }
    }
  }
 catch (  ClosedByInterruptException ex) {
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,this,"String_Node_Str" + con.getChannel().socket().getRemoteSocketAddress() + "String_Node_Str");
    }
    closeConnection(key);
  }
catch (  IOException ex) {
    if (Logging.isDebug()) {
      Logging.logMessage(Logging.LEVEL_DEBUG,this,ex);
    }
    closeConnection(key);
  }
}