[Demonstration 1]

[Buggy Method]
@Override
public void connect(SSLContext sslContextOverride) throws IOException {
    if (listener == null) {
        throw new IllegalStateException("A transport listener must be set before connection attempts.");
    }
    final SslHandler sslHandler;
    if (isSecure()) {
        try {
            TransportSslOptions sslOptions = getSslOptions();
            sslOptions.setSslContextOverride(sslContextOverride);
            sslHandler = TransportSupport.createSslHandler(getRemoteLocation(), sslOptions);
        } catch (Exception ex) {
            // TODO: can we stop it throwing Exception?
            throw IOExceptionSupport.create(ex);
        }
    } else {
        sslHandler = null;
    }
    if (getTransportOptions().isUseEpoll() || !Epoll.isAvailable()) {
        LOG.trace("Netty Transport using NIO mode");
        group = new NioEventLoopGroup(1);
    } else {
        LOG.trace("Netty Transport using Epoll mode");
        group = new EpollEventLoopGroup(1);
    }
    bootstrap = new Bootstrap();
    bootstrap.group(group);
    if (getTransportOptions().isUseEpoll() || !Epoll.isAvailable()) {
        bootstrap.channel(NioSocketChannel.class);
    } else {
        bootstrap.channel(EpollSocketChannel.class);
    }
    bootstrap.handler(new ChannelInitializer<Channel>() {

        @Override
        public void initChannel(Channel connectedChannel) throws Exception {
            configureChannel(connectedChannel, sslHandler);
        }
    });
    configureNetty(bootstrap, getTransportOptions());
    ChannelFuture future = bootstrap.connect(getRemoteHost(), getRemotePort());
    future.addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (!future.isSuccess()) {
                handleException(future.channel(), IOExceptionSupport.create(future.cause()));
            }
        }
    });
    try {
        connectLatch.await();
    } catch (InterruptedException ex) {
        LOG.debug("Transport connection was interrupted.");
        Thread.interrupted();
        failureCause = IOExceptionSupport.create(ex);
    }
    if (failureCause != null) {
        // Close out any Netty resources now as they are no longer needed.
        if (channel != null) {
            channel.close().syncUninterruptibly();
            channel = null;
        }
        if (group != null) {
            Future<?> fut = group.shutdownGracefully(0, SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
            if (!fut.awaitUninterruptibly(2 * SHUTDOWN_TIMEOUT)) {
                LOG.trace("Channel group shutdown failed to complete in allotted time");
            }
            group = null;
        }
        throw failureCause;
    } else {
        // Connected, allow any held async error to fire now and close the transport.
        channel.eventLoop().execute(new Runnable() {

            @Override
            public void run() {
                if (failureCause != null) {
                    channel.pipeline().fireExceptionCaught(failureCause);
                }
            }
        });
    }
}

[Buggy Hunk]
if (getTransportOptions().isUseEpoll() || !Epoll.isAvailable()) {

[Patch]
if (!getTransportOptions().isUseEpoll() || !Epoll.isAvailable()) {

[Demonstration 2]

[Buggy Method]
public void addSession(Session session) {
    synchronized (this.sessions) {
        if (this.sessions.contains(session)) {
            return;
        }
        this.sessions.add(session);
        this.sessionHeartbeats.add(new AtomicLong(Clock.currentTimeMillis()));
    }
}

[Buggy Hunk]
this.sessionHeartbeats.add(new AtomicLong(Clock.currentTimeMillis()));

[Patch]
this.sessionHeartbeats.put(session.getId(), Clock.currentTimeMillis());

[Demonstration 3]

[Buggy Method]
private void registerTypes(final Bootstrap<?> bootstrap) {
    bootstrap.getObjectMapper().registerSubtypes(new NamedType(RevolverHttpServiceConfig.class, "http"));
    bootstrap.getObjectMapper().registerSubtypes(new NamedType(RevolverHttpRequest.class, "http"));
    bootstrap.getObjectMapper().registerSubtypes(new NamedType(BasicAuthConfig.class, "basic"));
    bootstrap.getObjectMapper().registerSubtypes(new NamedType(TokenAuthConfig.class, "token"));
    bootstrap.getObjectMapper().registerSubtypes(new NamedType(SimpleEndpointSpec.class, "simple"));
    bootstrap.getObjectMapper().registerSubtypes(new NamedType(RangerEndpointSpec.class, "ranger_sharded"));
    bootstrap.getObjectMapper().registerSubtypes(new NamedType(InMemoryMailBoxConfig.class, "in_memory"));
    bootstrap.getObjectMapper().registerSubtypes(new NamedType(AerospikeMailBoxConfig.class, "aerospike"));
}

[Buggy Hunk]
bootstrap.getObjectMapper().registerSubtypes(new NamedType(RevolverHttpRequest.class, "http"));

[Patch]
bootstrap.getObjectMapper().registerSubtypes(new NamedType(RevolverHttpServiceConfig.class, "https"));