Program: 89271
Project: 89271
Buggy source:
public byte[] read(SocketChannel ch) throws IOException {
  if (_readHeader) {
    if (_readBuffer.position() == 0) {
      _readBuffer.limit(4);
    }
    if (ch.read(_readBuffer) == -1) {
      throw new IOException("String_Node_Str");
    }
    if (_readBuffer.hasRemaining()) {
      s_logger.trace("String_Node_Str");
      return null;
    }
    _readBuffer.flip();
    int header=_readBuffer.getInt();
    int readSize=(short)header;
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str" + readSize);
    }
    if (readSize > MAX_SIZE_PER_PACKET) {
      throw new IOException("String_Node_Str" + readSize);
    }
    if (!_gotFollowingPacket) {
      _plaintextBuffer=ByteBuffer.allocate(2000);
    }
    if ((header & HEADER_FLAG_FOLLOWING) != 0) {
      _gotFollowingPacket=true;
    }
 else {
      _gotFollowingPacket=false;
    }
    _readBuffer.clear();
    _readHeader=false;
    if (_readBuffer.capacity() < readSize) {
      if (s_logger.isTraceEnabled()) {
        s_logger.trace("String_Node_Str" + _readBuffer.capacity());
      }
      _readBuffer=ByteBuffer.allocate(readSize);
    }
    _readBuffer.limit(readSize);
  }
  if (ch.read(_readBuffer) == -1) {
    throw new IOException("String_Node_Str");
  }
  if (_readBuffer.hasRemaining()) {
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str" + _readBuffer.remaining());
    }
    return null;
  }
  _readBuffer.flip();
  ByteBuffer appBuf;
  SSLSession sslSession=_sslEngine.getSession();
  SSLEngineResult engResult;
  appBuf=ByteBuffer.allocate(sslSession.getApplicationBufferSize() + 40);
  engResult=_sslEngine.unwrap(_readBuffer,appBuf);
  if (engResult.getHandshakeStatus() != HandshakeStatus.FINISHED && engResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && engResult.getStatus() != SSLEngineResult.Status.OK) {
    throw new IOException("String_Node_Str" + engResult);
  }
  appBuf.flip();
  if (_plaintextBuffer.remaining() < appBuf.limit()) {
    ByteBuffer newBuffer=ByteBuffer.allocate(_plaintextBuffer.capacity() + appBuf.limit() * 5);
    _plaintextBuffer.flip();
    newBuffer.put(_plaintextBuffer);
    _plaintextBuffer=newBuffer;
  }
  _plaintextBuffer.put(appBuf);
  _readBuffer.clear();
  _readHeader=true;
  if (s_logger.isTraceEnabled()) {
    s_logger.trace("String_Node_Str" + appBuf.limit());
  }
  if (!_gotFollowingPacket) {
    _plaintextBuffer.flip();
    byte[] result=new byte[_plaintextBuffer.limit()];
    _plaintextBuffer.get(result);
    return result;
  }
 else {
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str");
    }
    return null;
  }
}

Fixed version (ground truth):
public byte[] read(SocketChannel ch) throws IOException {
  if (_readHeader) {
    if (_readBuffer.position() == 0) {
      _readBuffer.limit(4);
    }
    if (ch.read(_readBuffer) == -1) {
      throw new IOException("String_Node_Str");
    }
    if (_readBuffer.hasRemaining()) {
      s_logger.trace("String_Node_Str");
      return null;
    }
    _readBuffer.flip();
    int header=_readBuffer.getInt();
    int readSize=(short)header;
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str" + readSize);
    }
    if (readSize > MAX_SIZE_PER_PACKET) {
      throw new IOException("String_Node_Str" + readSize);
    }
    if (!_gotFollowingPacket) {
      _plaintextBuffer=ByteBuffer.allocate(2000);
    }
    if ((header & HEADER_FLAG_FOLLOWING) != 0) {
      _gotFollowingPacket=true;
    }
 else {
      _gotFollowingPacket=false;
    }
    _readBuffer.clear();
    _readHeader=false;
    if (_readBuffer.capacity() < readSize) {
      if (s_logger.isTraceEnabled()) {
        s_logger.trace("String_Node_Str" + _readBuffer.capacity());
      }
      _readBuffer=ByteBuffer.allocate(readSize);
    }
    _readBuffer.limit(readSize);
  }
  if (ch.read(_readBuffer) == -1) {
    throw new IOException("String_Node_Str");
  }
  if (_readBuffer.hasRemaining()) {
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str" + _readBuffer.remaining());
    }
    return null;
  }
  _readBuffer.flip();
  ByteBuffer appBuf;
  SSLSession sslSession=_sslEngine.getSession();
  SSLEngineResult engResult;
  int remaining=0;
  while (_readBuffer.hasRemaining()) {
    remaining=_readBuffer.remaining();
    appBuf=ByteBuffer.allocate(sslSession.getApplicationBufferSize() + 40);
    engResult=_sslEngine.unwrap(_readBuffer,appBuf);
    if (engResult.getHandshakeStatus() != HandshakeStatus.FINISHED && engResult.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && engResult.getStatus() != SSLEngineResult.Status.OK) {
      throw new IOException("String_Node_Str" + engResult);
    }
    if (remaining == _readBuffer.remaining()) {
      throw new IOException("String_Node_Str" + remaining + "String_Node_Str");
    }
    appBuf.flip();
    if (_plaintextBuffer.remaining() < appBuf.limit()) {
      ByteBuffer newBuffer=ByteBuffer.allocate(_plaintextBuffer.capacity() + appBuf.limit() * 5);
      _plaintextBuffer.flip();
      newBuffer.put(_plaintextBuffer);
      _plaintextBuffer=newBuffer;
    }
    _plaintextBuffer.put(appBuf);
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str" + appBuf.limit());
    }
  }
  _readBuffer.clear();
  _readHeader=true;
  if (!_gotFollowingPacket) {
    _plaintextBuffer.flip();
    byte[] result=new byte[_plaintextBuffer.limit()];
    _plaintextBuffer.get(result);
    return result;
  }
 else {
    if (s_logger.isTraceEnabled()) {
      s_logger.trace("String_Node_Str");
    }
    return null;
  }
}