Program: 4174
Project: 4174
Buggy source:
private void doTLSTest(final boolean testServer) throws Exception {
  Executor executor=ExecutorsHelper.newProcessingQueue("String_Node_Str");
  SSLContext context=SSLContext.getInstance("String_Node_Str");
  context.init(null,null,null);
  final SSLReadWriteChannel channel=new SSLReadWriteChannel(context,executor);
  SSLSocketFactory sslFactory=context.getSocketFactory();
  final SSLSocket sslSocket=(SSLSocket)sslFactory.createSocket();
  sslSocket.setUseClientMode(!testServer);
  sslSocket.setWantClientAuth(false);
  sslSocket.setNeedClientAuth(false);
  sslSocket.setEnabledCipherSuites(new String[]{"String_Node_Str"});
  ServerSocket server=new ServerSocket();
  server.bind(null);
  sslSocket.connect(server.getLocalSocketAddress());
  final Socket accepted=server.accept();
  NIODispatcher.instance().getScheduledExecutorService().submit(new Runnable(){
    public void run(){
      channel.initialize(accepted.getRemoteSocketAddress(),new String[]{"String_Node_Str"},testServer,false);
    }
  }
).get();
  IRWrapper irw=new IRWrapper(accepted.getInputStream());
  IWWrapper iww=new IWWrapper(accepted.getOutputStream());
  channel.setReadChannel(irw);
  channel.setWriteChannel(iww);
  final String INCOMING="String_Node_Str";
  final String OUTGOING="String_Node_Str";
  new WriteBufferChannel(OUTGOING.getBytes(),channel);
  final byte[] b=new byte[100];
  Thread t=new ManagedThread(new Runnable(){
    public void run(){
      try {
        sslSocket.getInputStream().read(b);
        sslSocket.getOutputStream().write(INCOMING.getBytes());
      }
 catch (      IOException iox) {
        throw new RuntimeException(iox);
      }
    }
  }
);
  t.start();
  final ByteBuffer channelRead=ByteBuffer.allocate(100);
  for (int i=0; i < 10; i++) {
    NIODispatcher.instance().getScheduledExecutorService().submit(new Runnable(){
      public void run(){
        try {
          channel.read(channelRead);
          channel.handleWrite();
        }
 catch (        IOException iox) {
          throw new RuntimeException(iox);
        }
      }
    }
).get();
    Thread.sleep(100);
  }
  t.join(10000);
  assertEquals(INCOMING,new String(channelRead.array(),0,channelRead.position()));
  assertEquals(OUTGOING,new String(b,0,OUTGOING.length()));
  assertEquals(irw.getTotalRead(),channel.getReadBytesConsumed());
  assertEquals(INCOMING.length(),channel.getReadBytesProduced());
  assertEquals(iww.getTotalWrote(),channel.getWrittenBytesProduced());
  assertEquals(OUTGOING.length(),channel.getWrittenBytesConsumed());
  assertGreaterThan(channel.getReadBytesProduced(),channel.getReadBytesConsumed());
  assertGreaterThan(channel.getWrittenBytesConsumed(),channel.getWrittenBytesProduced());
  sslSocket.close();
  server.close();
  accepted.close();
  channel.close();
  channel.shutdown();
}

Fixed version (ground truth):
private void doTLSTest(final boolean testServer) throws Exception {
  Executor executor=ExecutorsHelper.newProcessingQueue("String_Node_Str");
  SSLContext context=SSLContext.getInstance("String_Node_Str");
  context.init(null,null,null);
  final SSLReadWriteChannel channel=new SSLReadWriteChannel(context,executor,NIODispatcher.instance().getBufferCache(),NIODispatcher.instance().getScheduledExecutorService());
  SSLSocketFactory sslFactory=context.getSocketFactory();
  final SSLSocket sslSocket=(SSLSocket)sslFactory.createSocket();
  sslSocket.setUseClientMode(!testServer);
  sslSocket.setWantClientAuth(false);
  sslSocket.setNeedClientAuth(false);
  sslSocket.setEnabledCipherSuites(new String[]{"String_Node_Str"});
  ServerSocket server=new ServerSocket();
  server.bind(null);
  sslSocket.connect(server.getLocalSocketAddress());
  final Socket accepted=server.accept();
  NIODispatcher.instance().getScheduledExecutorService().submit(new Runnable(){
    public void run(){
      channel.initialize(accepted.getRemoteSocketAddress(),new String[]{"String_Node_Str"},testServer,false);
    }
  }
).get();
  IRWrapper irw=new IRWrapper(accepted.getInputStream());
  IWWrapper iww=new IWWrapper(accepted.getOutputStream());
  channel.setReadChannel(irw);
  channel.setWriteChannel(iww);
  final String INCOMING="String_Node_Str";
  final String OUTGOING="String_Node_Str";
  new WriteBufferChannel(OUTGOING.getBytes(),channel);
  final byte[] b=new byte[100];
  Thread t=new ManagedThread(new Runnable(){
    public void run(){
      try {
        sslSocket.getInputStream().read(b);
        sslSocket.getOutputStream().write(INCOMING.getBytes());
      }
 catch (      IOException iox) {
        throw new RuntimeException(iox);
      }
    }
  }
);
  t.start();
  final ByteBuffer channelRead=ByteBuffer.allocate(100);
  for (int i=0; i < 10; i++) {
    NIODispatcher.instance().getScheduledExecutorService().submit(new Runnable(){
      public void run(){
        try {
          channel.read(channelRead);
          channel.handleWrite();
        }
 catch (        IOException iox) {
          throw new RuntimeException(iox);
        }
      }
    }
).get();
    Thread.sleep(100);
  }
  t.join(10000);
  assertEquals(INCOMING,new String(channelRead.array(),0,channelRead.position()));
  assertEquals(OUTGOING,new String(b,0,OUTGOING.length()));
  assertEquals(irw.getTotalRead(),channel.getReadBytesConsumed());
  assertEquals(INCOMING.length(),channel.getReadBytesProduced());
  assertEquals(iww.getTotalWrote(),channel.getWrittenBytesProduced());
  assertEquals(OUTGOING.length(),channel.getWrittenBytesConsumed());
  assertGreaterThan(channel.getReadBytesProduced(),channel.getReadBytesConsumed());
  assertGreaterThan(channel.getWrittenBytesConsumed(),channel.getWrittenBytesProduced());
  sslSocket.close();
  server.close();
  accepted.close();
  channel.close();
  channel.shutdown();
}