nus-yam/ex-repair huggingface dataset:
Program: 141
Project: 141
Buggy source:
public final void done(Callable callable){
  try {
    if (exEx.get() != null) {
      return;
    }
    if (reaperFuture != null)     reaperFuture.cancel(true);
    getContent();
    isDone.set(true);
    if (callable != null) {
      try {
        callable.call();
      }
 catch (      Exception ex) {
        throw new RuntimeException(ex);
      }
    }
  }
 catch (  RuntimeException t) {
    exEx.compareAndSet(null,new ExecutionException(t));
  }
 finally {
    latch.countDown();
  }
}

Fixed version (ground truth):
public final void done(Callable callable){
  try {
    if (exEx.get() != null) {
      return;
    }
    if (reaperFuture != null)     reaperFuture.cancel(true);
    getContent();
    isDone.set(true);
    if (callable != null) {
      try {
        callable.call();
      }
 catch (      Exception ex) {
        throw new RuntimeException(ex);
      }
    }
  }
 catch (  ExecutionException t) {
    return;
  }
catch (  RuntimeException t) {
    exEx.compareAndSet(null,new ExecutionException(t));
  }
 finally {
    latch.countDown();
  }
}
Program: 143
Project: 143
Buggy source:
@Test(groups="String_Node_Str") public void redirectAndBasicAuthTest() throws Exception, ExecutionException, TimeoutException, InterruptedException {
  try {
    setUpSecondServer();
    AsyncHttpClient client=new AsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build());
    AsyncHttpClient.BoundRequestBuilder r=client.prepareGet(getTargetUrl2()).setHeader("String_Node_Str",getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build());
    Future<Response> f=r.execute();
    Response resp=f.get(30,TimeUnit.SECONDS);
    assertNotNull(resp);
    assertNotNull(resp.getHeader("String_Node_Str"));
    assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
  }
  finally {
    stopSecondServer();
  }
}

Fixed version (ground truth):
@Test(groups="String_Node_Str") public void redirectAndBasicAuthTest() throws Exception, ExecutionException, TimeoutException, InterruptedException {
  try {
    setUpSecondServer();
    AsyncHttpClient client=new AsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build());
    AsyncHttpClient.BoundRequestBuilder r=client.prepareGet(getTargetUrl2()).setHeader("String_Node_Str","String_Node_Str").setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build());
    Future<Response> f=r.execute();
    Response resp=f.get(30,TimeUnit.SECONDS);
    assertEquals(resp.getStatusCode(),HttpServletResponse.SC_OK);
    assertNotNull(resp);
    assertNotNull(resp.getHeader("String_Node_Str"));
  }
  finally {
    stopSecondServer();
  }
}
Program: 144
Project: 144
Buggy source:
private void setUpSecondServer() throws Exception {
  server2=new Server();
  port2=findFreePort();
  Connector listener=new SelectChannelConnector();
  listener.setHost("String_Node_Str");
  listener.setPort(port2);
  server2.addConnector(listener);
  server2.setHandler(new RedirectHandler());
  server2.start();
}

Fixed version (ground truth):
private void setUpSecondServer() throws Exception {
  server2=new Server();
  port2=findFreePort();
  Connector listener=new SelectChannelConnector();
  listener.setHost("String_Node_Str");
  listener.setPort(port2);
  server2.addConnector(listener);
  LoginService loginService=new HashLoginService("String_Node_Str","String_Node_Str");
  server2.addBean(loginService);
  Constraint constraint=new Constraint();
  constraint.setName(Constraint.__BASIC_AUTH);
  constraint.setRoles(new String[]{user,admin});
  constraint.setAuthenticate(true);
  ConstraintMapping mapping=new ConstraintMapping();
  mapping.setConstraint(constraint);
  mapping.setPathSpec("String_Node_Str");
  Set<String> knownRoles=new HashSet<String>();
  knownRoles.add(user);
  knownRoles.add(admin);
  ConstraintSecurityHandler security=new ConstraintSecurityHandler(){
    @Override public void handle(    String arg0,    Request arg1,    HttpServletRequest arg2,    HttpServletResponse arg3) throws IOException, ServletException {
      System.err.println("String_Node_Str");
      System.err.println("String_Node_Str" + arg2.getHeader("String_Node_Str"));
      System.err.println("String_Node_Str" + arg2.getRequestURI());
      super.handle(arg0,arg1,arg2,arg3);
    }
  }
;
  security.setConstraintMappings(new ConstraintMapping[]{mapping},knownRoles);
  security.setAuthenticator(new BasicAuthenticator());
  security.setLoginService(loginService);
  security.setStrict(true);
  security.setHandler(new RedirectHandler());
  server2.setHandler(security);
  server2.start();
}
Program: 145
Project: 145
Buggy source:
protected String getTargetUrl(){
  return "String_Node_Str" + port1 + "String_Node_Str";
}

Fixed version (ground truth):
@Override protected String getTargetUrl(){
  return "String_Node_Str" + port1 + "String_Node_Str";
}
Program: 147
Project: 147
Buggy source:
@Override public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent e) throws Exception {
  Channel channel=e.getChannel();
  Throwable cause=e.getCause();
  if (ctx.getAttachment() instanceof NettyResponseFuture<?>) {
    NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
    future.attachChannel(null);
    if (cause != null && ClosedChannelException.class.isAssignableFrom(cause.getClass())) {
      return;
    }
    if (abortOnRemoteCloseException(cause)) {
      log.debug(currentThread() + String.format("String_Node_Str",channel));
      remotelyClosed(channel,null);
      return;
    }
    if (future != null) {
      try {
        abort(future,cause);
      }
 catch (      Throwable t) {
        log.error(currentThread(),t);
      }
    }
  }
  if (log.isDebugEnabled()) {
    log.error(currentThread() + String.format("String_Node_Str",cause != null ? cause.getMessage() : "String_Node_Str"));
    log.error(cause);
  }
}

Fixed version (ground truth):
@Override public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent e) throws Exception {
  Channel channel=e.getChannel();
  Throwable cause=e.getCause();
  NettyResponseFuture<?> future=null;
  if (ctx.getAttachment() instanceof NettyResponseFuture<?>) {
    future=(NettyResponseFuture<?>)ctx.getAttachment();
    future.attachChannel(null);
    if (cause != null && ClosedChannelException.class.isAssignableFrom(cause.getClass())) {
      return;
    }
    if (abortOnRemoteCloseException(cause)) {
      log.debug(currentThread() + String.format("String_Node_Str",channel));
      remotelyClosed(channel,null);
      return;
    }
  }
 else   if (ctx.getAttachment() instanceof AsyncCallable) {
    future=((AsyncCallable)ctx.getAttachment()).future();
  }
  if (future != null) {
    try {
      abort(future,cause);
    }
 catch (    Throwable t) {
      log.error(currentThread(),t);
    }
  }
  if (log.isDebugEnabled()) {
    log.error(currentThread() + String.format("String_Node_Str",cause != null ? cause.getMessage() : "String_Node_Str",ctx.getAttachment()));
    log.error(cause);
  }
}
Program: 149
Project: 149
Buggy source:
public void channelClosed(ChannelHandlerContext ctx,ChannelStateEvent e) throws Exception {
  Exception exception=null;
  try {
    super.channelClosed(ctx,e);
  }
 catch (  Exception ex) {
    exception=ex;
  }
  if (log.isDebugEnabled()) {
    log.debug(String.format(currentThread() + "String_Node_Str",e.getChannel()));
  }
  if (ctx.getAttachment() instanceof Callable<?>) {
    ((Callable)ctx.getAttachment()).call();
    ctx.setAttachment(null);
    return;
  }
  connectionsPool.removeAllConnections(ctx.getChannel());
  if (!isClose.get() && ctx.getAttachment() instanceof NettyResponseFuture<?>) {
    NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
    if (Boolean.class.isAssignableFrom(e.getValue().getClass()) && !Boolean.class.cast(e.getValue())) {
      if (remotelyClosed(ctx.getChannel(),future)) {
        return;
      }
    }
    if (future != null && !future.isDone() && !future.isCancelled()) {
      if (config.getMaxTotalConnections() != -1) {
        maxConnections.decrementAndGet();
      }
      try {
        future.getAsyncHandler().onThrowable(exception != null ? exception : new IOException("String_Node_Str"));
      }
 catch (      Throwable t) {
        log.error(String.format(currentThread() + "String_Node_Str"),t);
      }
    }
  }
}

Fixed version (ground truth):
public void channelClosed(ChannelHandlerContext ctx,ChannelStateEvent e) throws Exception {
  Exception exception=null;
  try {
    super.channelClosed(ctx,e);
  }
 catch (  Exception ex) {
    exception=ex;
  }
  if (log.isDebugEnabled()) {
    log.debug(String.format(currentThread() + "String_Node_Str",e.getChannel()));
  }
  if (ctx.getAttachment() instanceof AsyncCallable) {
    ((AsyncCallable)ctx.getAttachment()).call();
    ctx.setAttachment(null);
    return;
  }
  connectionsPool.removeAllConnections(ctx.getChannel());
  if (!isClose.get() && ctx.getAttachment() instanceof NettyResponseFuture<?>) {
    NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
    if (Boolean.class.isAssignableFrom(e.getValue().getClass()) && !Boolean.class.cast(e.getValue())) {
      if (remotelyClosed(ctx.getChannel(),future)) {
        return;
      }
    }
    if (future != null && !future.isDone() && !future.isCancelled()) {
      if (config.getMaxTotalConnections() != -1) {
        maxConnections.decrementAndGet();
      }
      try {
        future.getAsyncHandler().onThrowable(exception != null ? exception : new IOException("String_Node_Str"));
      }
 catch (      Throwable t) {
        log.error(String.format(currentThread() + "String_Node_Str"),t);
      }
    }
  }
}
Program: 150
Project: 150
Buggy source:
private Channel lookupInCache(URI uri){
  Channel channel=connectionsPool.removeConnection(AsyncHttpProviderUtils.getBaseUrl(uri));
  if (channel != null) {
    if (log.isDebugEnabled()) {
      log.debug(String.format(currentThread() + "String_Node_Str",uri,channel));
    }
    if (channel.isOpen()) {
      channel.setReadable(true);
    }
 else {
      return null;
    }
    try {
      return verifyChannelPipeline(channel,uri.getScheme());
    }
 catch (    Exception ex) {
      if (log.isDebugEnabled()) {
        log.warn(ex);
      }
    }
  }
  return null;
}

Fixed version (ground truth):
private Channel lookupInCache(URI uri){
  Channel channel=connectionsPool.removeConnection(AsyncHttpProviderUtils.getBaseUrl(uri));
  if (channel != null) {
    if (log.isDebugEnabled()) {
      log.debug(String.format(currentThread() + "String_Node_Str",uri,channel));
    }
    if (channel.isOpen()) {
      channel.setReadable(true);
    }
 else {
      return null;
    }
    try {
      return verifyChannelPipeline(channel,uri.getScheme());
    }
 catch (    Exception ex) {
      if (log.isDebugEnabled()) {
        log.warn(currentThread() + "String_Node_Str");
        log.warn(ex);
      }
    }
  }
  return null;
}
Program: 151
Project: 151
Buggy source:
public Boolean call() throws Exception {
  if (future.getKeepAlive()) {
    return connectionsPool.addConnection(AsyncHttpProviderUtils.getBaseUrl(future.getURI()),ctx.getChannel());
  }
  return false;
}

Fixed version (ground truth):
abstract public Object call() throws Exception ;
Program: 154
Project: 154
Buggy source:
/** 
 * {@inheritDoc}
 */
public V get(long l,TimeUnit tu) throws InterruptedException, TimeoutException, ExecutionException {
  if (!isDone() && !isCancelled()) {
    boolean failed=false;
    if (l == -1) {
      latch.await();
    }
 else {
      failed=!latch.await(l,tu);
      if (responseTimeoutInMs != -1 && ((System.currentTimeMillis() - touch.get()) <= responseTimeoutInMs)) {
        return get(l,tu);
      }
    }
    if (failed) {
      isCancelled.set(true);
      TimeoutException te=new TimeoutException(String.format("String_Node_Str",responseTimeoutInMs));
      try {
        asyncHandler.onThrowable(te);
      }
  finally {
        throw te;
      }
    }
    isDone.set(true);
    ExecutionException e=exEx.getAndSet(null);
    if (e != null) {
      throw e;
    }
  }
  return getContent();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
public V get(long l,TimeUnit tu) throws InterruptedException, TimeoutException, ExecutionException {
  if (!isDone() && !isCancelled()) {
    boolean expired=false;
    if (l == -1) {
      latch.await();
    }
 else {
      expired=!latch.await(l,tu);
      if (!contentProcessed.get() && expired && l != -1 && ((System.currentTimeMillis() - touch.get()) <= l)) {
        return get(l,tu);
      }
    }
    if (expired) {
      isCancelled.set(true);
      TimeoutException te=new TimeoutException(String.format("String_Node_Str",l));
      try {
        asyncHandler.onThrowable(te);
      }
  finally {
        throw te;
      }
    }
    isDone.set(true);
    ExecutionException e=exEx.getAndSet(null);
    if (e != null) {
      throw e;
    }
  }
  return getContent();
}
Program: 157
Project: 157
Buggy source:
@Override public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent e) throws Exception {
  Channel channel=e.getChannel();
  Throwable cause=e.getCause();
  if (log.isDebugEnabled()) {
    log.error(currentThread() + String.format("String_Node_Str",cause != null ? cause.getMessage() : "String_Node_Str"));
    log.error(currentThread(),cause);
  }
  if (ctx.getAttachment() instanceof NettyResponseFuture<?>) {
    NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
    if (cause != null && ClosedChannelException.class.isAssignableFrom(cause.getClass())) {
      return;
    }
    if (cause != null && cause.getMessage() != null && (cause.getMessage().equalsIgnoreCase(WINXP_DISCONNECTION) || cause.getMessage().equalsIgnoreCase(WIN7_DISCONNECTION))) {
      remotelyClosed(channel,null);
      return;
    }
    if (future != null) {
      try {
        abort(future,cause);
      }
 catch (      Throwable t) {
        log.error(currentThread(),t);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent e) throws Exception {
  Channel channel=e.getChannel();
  Throwable cause=e.getCause();
  if (log.isDebugEnabled()) {
    log.error(currentThread() + String.format("String_Node_Str",cause != null ? cause.getMessage() : "String_Node_Str"));
    log.error(currentThread(),cause);
  }
  if (ctx.getAttachment() instanceof NettyResponseFuture<?>) {
    NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
    if (cause != null && ClosedChannelException.class.isAssignableFrom(cause.getClass())) {
      return;
    }
    if (cause != null && cause.getMessage() != null && (IOException.class.isAssignableFrom(cause.getClass())) && !channel.isReadable()) {
      remotelyClosed(channel,null);
      return;
    }
    if (future != null) {
      try {
        abort(future,cause);
      }
 catch (      Throwable t) {
        log.error(currentThread(),t);
      }
    }
  }
}
Program: 159
Project: 159
Buggy source:
public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
  response.setStatus(HttpServletResponse.SC_OK);
  try {
    response.getOutputStream().print(MSG);
    response.getOutputStream().flush();
    Thread.sleep(3000);
    response.getOutputStream().print(MSG);
    response.getOutputStream().flush();
  }
 catch (  InterruptedException e) {
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
  }
}

Fixed version (ground truth):
public void handle(String target,Request baseRequest,HttpServletRequest request,final HttpServletResponse response) throws IOException, ServletException {
  response.setStatus(HttpServletResponse.SC_OK);
  final Continuation continuation=ContinuationSupport.getContinuation(request);
  continuation.suspend();
  new Thread(new Runnable(){
    public void run(){
      try {
        Thread.sleep(1500);
        response.getOutputStream().print(MSG);
        response.getOutputStream().flush();
      }
 catch (      InterruptedException e) {
        log.error(e);
      }
catch (      IOException e) {
        log.error(e);
      }
    }
  }
).start();
  new Thread(new Runnable(){
    public void run(){
      try {
        Thread.sleep(3000);
        response.getOutputStream().print(MSG);
        response.getOutputStream().flush();
        continuation.complete();
      }
 catch (      InterruptedException e) {
        log.error(e);
      }
catch (      IOException e) {
        log.error(e);
      }
    }
  }
).start();
  baseRequest.setHandled(true);
}
Program: 160
Project: 160
Buggy source:
public int writeTo(OutputStream outputStream) throws IOException {
  return writeTo(outputStream);
}

Fixed version (ground truth):
public int writeTo(OutputStream outputStream) throws IOException {
  if (chunk != null) {
    ChannelBuffer b=chunk.getContent();
    b.readBytes(outputStream,b.readableBytes());
    return b.readableBytes();
  }
 else {
    ChannelBuffer b=response.getContent();
    b.readBytes(outputStream,b.readableBytes());
    return b.readableBytes();
  }
}
Program: 161
Project: 161
Buggy source:
public RequestImpl(Request prototype){
  if (prototype != null) {
    this.type=prototype.getType();
    int pos=prototype.getUrl().indexOf("String_Node_Str");
    this.url=pos > 0 ? prototype.getUrl().substring(0,pos) : prototype.getUrl();
    this.headers=new FluentCaseInsensitiveStringsMap(prototype.getHeaders());
    this.cookies=new ArrayList<Cookie>(prototype.getCookies());
    this.byteData=prototype.getByteData();
    this.stringData=prototype.getStringData();
    this.streamData=prototype.getStreamData();
    this.entityWriter=prototype.getEntityWriter();
    this.params=(prototype.getParams() == null ? null : new FluentStringsMap(prototype.getParams()));
    this.queryParams=(prototype.getQueryParams() == null ? null : new FluentStringsMap(prototype.getQueryParams()));
    this.parts=(prototype.getParts() == null ? null : new ArrayList<Part>(prototype.getParts()));
    this.virtualHost=prototype.getVirtualHost();
    this.length=prototype.getLength();
    this.proxyServer=prototype.getProxyServer();
    this.realm=prototype.getRealm();
    this.file=prototype.getFile();
  }
}

Fixed version (ground truth):
public RequestImpl(Request prototype){
  if (prototype != null) {
    this.type=prototype.getType();
    int pos=prototype.getUrl().indexOf("String_Node_Str");
    this.url=pos > 0 ? prototype.getUrl().substring(0,pos) : prototype.getUrl();
    this.headers=new FluentCaseInsensitiveStringsMap(prototype.getHeaders());
    this.cookies=new ArrayList<Cookie>(prototype.getCookies());
    this.byteData=prototype.getByteData();
    this.stringData=prototype.getStringData();
    this.streamData=prototype.getStreamData();
    this.entityWriter=prototype.getEntityWriter();
    this.params=(prototype.getParams() == null ? null : new FluentStringsMap(prototype.getParams()));
    this.queryParams=(prototype.getQueryParams() == null ? null : new FluentStringsMap(prototype.getQueryParams()));
    this.parts=(prototype.getParts() == null ? null : new ArrayList<Part>(prototype.getParts()));
    this.virtualHost=prototype.getVirtualHost();
    this.length=prototype.getLength();
    this.proxyServer=prototype.getProxyServer();
    this.realm=prototype.getRealm();
    this.file=prototype.getFile();
    this.perRequestConfig=prototype.getPerRequestConfig();
  }
}
Program: 163
Project: 163
Buggy source:
public Object call(){
  if (!future.isDone() && !future.isCancelled()) {
    future.abort(new TimeoutException());
    channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(ClosedEvent.class);
  }
  return null;
}

Fixed version (ground truth):
public Object call(){
  if (!future.isDone() && !future.isCancelled()) {
    future.abort(new TimeoutException("String_Node_Str"));
    channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(ClosedEvent.class);
  }
  return null;
}
Program: 164
Project: 164
Buggy source:
public ConnectListener<T> build() throws IOException {
  URI uri=createUri(request.getRawUrl());
  HttpRequest nettyRequest=buildRequest(config,request,uri,true);
  log.debug("String_Node_Str",asyncHandler);
  if (future == null) {
    future=new NettyResponseFuture<T>(uri,request,asyncHandler,nettyRequest,config.getRequestTimeoutInMs());
  }
  return new ConnectListener<T>(config,future,nettyRequest);
}

Fixed version (ground truth):
public ConnectListener<T> build() throws IOException {
  URI uri=createUri(request.getRawUrl());
  HttpRequest nettyRequest=buildRequest(config,request,uri,true);
  log.debug("String_Node_Str",asyncHandler);
  if (future == null) {
    future=new NettyResponseFuture<T>(uri,request,asyncHandler,nettyRequest,requestTimeout(config,request.getPerRequestConfig()));
  }
  return new ConnectListener<T>(config,future,nettyRequest);
}
Program: 166
Project: 166
Buggy source:
public String getUrl(){
  if (url == null)   throw new NullPointerException("String_Node_Str");
  String uri;
  try {
    uri=URI.create(url).toURL().toString();
  }
 catch (  MalformedURLException e) {
    throw new IllegalStateException("String_Node_Str",e);
  }
  if (queryParams != null) {
    StringBuilder builder=new StringBuilder();
    if (!url.substring(8).contains("String_Node_Str")) {
      builder.append("String_Node_Str");
    }
    builder.append(url.contains("String_Node_Str") ? "String_Node_Str" : "String_Node_Str");
    for (Iterator<Entry<String,List<String>>> i=queryParams.iterator(); i.hasNext(); ) {
      Map.Entry<String,List<String>> param=i.next();
      String name=param.getKey();
      for (Iterator<String> j=param.getValue().iterator(); j.hasNext(); ) {
        String value=j.next();
        builder.append(name);
        if (value != null) {
          builder.append('=');
          builder.append(value);
        }
        if (j.hasNext()) {
          builder.append('&');
        }
      }
      if (i.hasNext()) {
        builder.append('&');
      }
    }
    uri+=builder.toString();
  }
  return uri;
}

Fixed version (ground truth):
public String getUrl(){
  if (url == null)   throw new NullPointerException("String_Node_Str");
  String uri;
  try {
    uri=URI.create(url).toURL().toString();
  }
 catch (  MalformedURLException e) {
    throw new IllegalStateException("String_Node_Str",e);
  }
  if (queryParams != null) {
    StringBuilder builder=new StringBuilder();
    if (!url.substring(8).contains("String_Node_Str")) {
      builder.append("String_Node_Str");
    }
    builder.append(url.contains("String_Node_Str") ? "String_Node_Str" : "String_Node_Str");
    for (Iterator<Entry<String,List<String>>> i=queryParams.iterator(); i.hasNext(); ) {
      Map.Entry<String,List<String>> param=i.next();
      String name=param.getKey();
      for (Iterator<String> j=param.getValue().iterator(); j.hasNext(); ) {
        String value=j.next();
        builder.append(name);
        if (value != null) {
          builder.append('=');
          try {
            builder.append(URLEncoder.encode(value,"String_Node_Str").replace("String_Node_Str","String_Node_Str"));
          }
 catch (          UnsupportedEncodingException e) {
            throw new AssertionError("String_Node_Str");
          }
        }
        if (j.hasNext()) {
          builder.append('&');
        }
      }
      if (i.hasNext()) {
        builder.append('&');
      }
    }
    uri+=builder.toString();
  }
  return uri;
}
Program: 167
Project: 167
Buggy source:
public void close(){
  isClose.set(true);
  connectionsPool.clear();
  openChannels.close();
  timer.stop();
  config.reaper().shutdown();
  config.executorService().shutdown();
  socketChannelFactory.releaseExternalResources();
  bootstrap.releaseExternalResources();
}

Fixed version (ground truth):
public void close(){
  isClose.set(true);
  connectionsPool.clear();
  openChannels.close();
  this.releaseExternalResources();
  config.reaper().shutdown();
  config.executorService().shutdown();
  socketChannelFactory.releaseExternalResources();
  bootstrap.releaseExternalResources();
}
Program: 168
Project: 168
Buggy source:
@Override protected void channelIdle(ChannelHandlerContext ctx,IdleState state,long lastActivityTimeMillis) throws Exception {
  ctx.getChannel().close();
  for (  Entry<String,Channel> e : connectionsPool.entrySet()) {
    if (e.getValue().equals(ctx.getChannel())) {
      connectionsPool.remove(e.getKey());
      activeConnectionsCount.decrementAndGet();
      return;
    }
  }
}

Fixed version (ground truth):
@Override protected void channelIdle(ChannelHandlerContext ctx,IdleState state,long lastActivityTimeMillis) throws Exception {
  NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
  closeChannel(ctx);
  for (  Entry<String,Channel> e : connectionsPool.entrySet()) {
    if (e.getValue().equals(ctx.getChannel())) {
      connectionsPool.remove(e.getKey());
      activeConnectionsCount.decrementAndGet();
      break;
    }
  }
  future.abort(new IOException("String_Node_Str" + config.getIdleConnectionTimeoutInMs()));
}
Program: 169
Project: 169
Buggy source:
public NettyAsyncHttpProvider(AsyncHttpClientConfig config){
  socketChannelFactory=new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),config.executorService());
  bootstrap=new ClientBootstrap(socketChannelFactory);
  this.config=config;
}

Fixed version (ground truth):
public NettyAsyncHttpProvider(AsyncHttpClientConfig config){
  super(new HashedWheelTimer(),0,0,config.getIdleConnectionTimeoutInMs(),TimeUnit.MILLISECONDS);
  socketChannelFactory=new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),config.executorService());
  bootstrap=new ClientBootstrap(socketChannelFactory);
  this.config=config;
}
Program: 170
Project: 170
Buggy source:
void configure(final boolean useSSL,final ConnectListener<?> cl){
  bootstrap.setPipelineFactory(new ChannelPipelineFactory(){
    public ChannelPipeline getPipeline() throws Exception {
      ChannelPipeline pipeline=pipeline();
      if (useSSL) {
        try {
          SSLEngine sslEngine=config.getSSLEngine();
          if (sslEngine == null) {
            sslEngine=SslUtils.getSSLEngine();
          }
          pipeline.addLast("String_Node_Str",new SslHandler(sslEngine));
        }
 catch (        Throwable ex) {
          cl.future().abort(ex);
        }
      }
      pipeline.addLast("String_Node_Str",new HttpClientCodec());
      if (config.isCompressionEnabled()) {
        pipeline.addLast("String_Node_Str",new HttpContentDecompressor());
      }
      IdleStateHandler h=new IdleStateHandler(timer,0,0,config.getIdleConnectionTimeoutInMs(),TimeUnit.MILLISECONDS){
        @Override protected void channelIdle(        ChannelHandlerContext ctx,        IdleState state,        long lastActivityTimeMillis) throws Exception {
          ctx.getChannel().close();
          for (          Entry<String,Channel> e : connectionsPool.entrySet()) {
            if (e.getValue().equals(ctx.getChannel())) {
              connectionsPool.remove(e.getKey());
              activeConnectionsCount.decrementAndGet();
              return;
            }
          }
        }
      }
;
      pipeline.addLast("String_Node_Str",h);
      pipeline.addLast("String_Node_Str",NettyAsyncHttpProvider.this);
      return pipeline;
    }
  }
);
}

Fixed version (ground truth):
void configure(final boolean useSSL,final ConnectListener<?> cl){
  bootstrap.setPipelineFactory(new ChannelPipelineFactory(){
    public ChannelPipeline getPipeline() throws Exception {
      ChannelPipeline pipeline=pipeline();
      if (useSSL) {
        try {
          SSLEngine sslEngine=config.getSSLEngine();
          if (sslEngine == null) {
            sslEngine=SslUtils.getSSLEngine();
          }
          pipeline.addLast("String_Node_Str",new SslHandler(sslEngine));
        }
 catch (        Throwable ex) {
          cl.future().abort(ex);
        }
      }
      pipeline.addLast("String_Node_Str",new HttpClientCodec());
      if (config.isCompressionEnabled()) {
        pipeline.addLast("String_Node_Str",new HttpContentDecompressor());
      }
      pipeline.addLast("String_Node_Str",NettyAsyncHttpProvider.this);
      return pipeline;
    }
  }
);
}
Program: 171
Project: 171
Buggy source:
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline=pipeline();
  if (useSSL) {
    try {
      SSLEngine sslEngine=config.getSSLEngine();
      if (sslEngine == null) {
        sslEngine=SslUtils.getSSLEngine();
      }
      pipeline.addLast("String_Node_Str",new SslHandler(sslEngine));
    }
 catch (    Throwable ex) {
      cl.future().abort(ex);
    }
  }
  pipeline.addLast("String_Node_Str",new HttpClientCodec());
  if (config.isCompressionEnabled()) {
    pipeline.addLast("String_Node_Str",new HttpContentDecompressor());
  }
  IdleStateHandler h=new IdleStateHandler(timer,0,0,config.getIdleConnectionTimeoutInMs(),TimeUnit.MILLISECONDS){
    @Override protected void channelIdle(    ChannelHandlerContext ctx,    IdleState state,    long lastActivityTimeMillis) throws Exception {
      ctx.getChannel().close();
      for (      Entry<String,Channel> e : connectionsPool.entrySet()) {
        if (e.getValue().equals(ctx.getChannel())) {
          connectionsPool.remove(e.getKey());
          activeConnectionsCount.decrementAndGet();
          return;
        }
      }
    }
  }
;
  pipeline.addLast("String_Node_Str",h);
  pipeline.addLast("String_Node_Str",NettyAsyncHttpProvider.this);
  return pipeline;
}

Fixed version (ground truth):
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline=pipeline();
  if (useSSL) {
    try {
      SSLEngine sslEngine=config.getSSLEngine();
      if (sslEngine == null) {
        sslEngine=SslUtils.getSSLEngine();
      }
      pipeline.addLast("String_Node_Str",new SslHandler(sslEngine));
    }
 catch (    Throwable ex) {
      cl.future().abort(ex);
    }
  }
  pipeline.addLast("String_Node_Str",new HttpClientCodec());
  if (config.isCompressionEnabled()) {
    pipeline.addLast("String_Node_Str",new HttpContentDecompressor());
  }
  pipeline.addLast("String_Node_Str",NettyAsyncHttpProvider.this);
  return pipeline;
}
Program: 172
Project: 172
Buggy source:
private void finishUpdate(NettyResponseFuture<?> future,ChannelHandlerContext ctx) throws IOException {
  ctx.setAttachment(new DiscardEvent());
  try {
    ctx.getChannel().setReadable(false);
  }
 catch (  Exception ex) {
    if (log.isTraceEnabled()) {
      log.trace(ex);
    }
  }
  markAsDoneAndCacheConnection(future,ctx.getChannel());
}

Fixed version (ground truth):
private void finishUpdate(NettyResponseFuture<?> future,ChannelHandlerContext ctx) throws IOException {
  closeChannel(ctx);
  markAsDoneAndCacheConnection(future,ctx.getChannel());
}
Program: 175
Project: 175
Buggy source:
private void markAsDoneAndCacheConnection(final NettyResponseFuture<?> future,final Channel channel) throws MalformedURLException {
  if (future.getKeepAlive() && maxConnectionsPerHost++ < config.getMaxConnectionPerHost()) {
    connectionsPool.put(future.getUrl().getBaseUrl(),channel);
  }
 else {
    connectionsPool.remove(future.getUrl().getBaseUrl());
  }
  future.done();
}

Fixed version (ground truth):
private void markAsDoneAndCacheConnection(final NettyResponseFuture<?> future,final Channel channel) throws MalformedURLException {
  if (future.getKeepAlive() && maxConnectionsPerHost++ < config.getMaxConnectionPerHost()) {
    connectionsPool.put(future.getUrl().getBaseUrl(),channel);
  }
 else {
    activeConnectionsCount.decrementAndGet();
  }
  future.done();
}
Program: 176
Project: 176
Buggy source:
@Override protected void channelIdle(ChannelHandlerContext ctx,IdleState state,long lastActivityTimeMillis) throws Exception {
  ctx.getChannel().close();
  removeFromCache(ctx);
}

Fixed version (ground truth):
@Override protected void channelIdle(ChannelHandlerContext ctx,IdleState state,long lastActivityTimeMillis) throws Exception {
  ctx.getChannel().close();
  for (  Entry<String,Channel> e : connectionsPool.entrySet()) {
    if (e.getValue().equals(ctx.getChannel())) {
      connectionsPool.remove(e.getKey());
      return;
    }
  }
}
Program: 177
Project: 177
Buggy source:
public void channelClosed(ChannelHandlerContext ctx,ChannelStateEvent e) throws Exception {
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + e.getState().toString());
  if (!isClose.get() && ctx.getAttachment() instanceof NettyResponseFuture<?>) {
    NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
    if (future != null && !future.isDone() && !future.isCancelled()) {
      future.getAsyncHandler().onThrowable(new IOException("String_Node_Str"));
    }
  }
  removeFromCache(ctx);
  ctx.sendUpstream(e);
}

Fixed version (ground truth):
public void channelClosed(ChannelHandlerContext ctx,ChannelStateEvent e) throws Exception {
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + e.getState().toString());
  if (!isClose.get() && ctx.getAttachment() instanceof NettyResponseFuture<?>) {
    NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
    if (future != null && !future.isDone() && !future.isCancelled()) {
      future.getAsyncHandler().onThrowable(new IOException("String_Node_Str"));
    }
  }
  ctx.sendUpstream(e);
}
Program: 178
Project: 178
Buggy source:
void configure(final boolean useSSL,final ConnectListener<?> cl){
  bootstrap.setPipelineFactory(new ChannelPipelineFactory(){
    public ChannelPipeline getPipeline() throws Exception {
      ChannelPipeline pipeline=pipeline();
      if (useSSL) {
        try {
          SSLEngine sslEngine=config.getSSLEngine();
          if (sslEngine == null) {
            sslEngine=SslUtils.getSSLEngine();
          }
          pipeline.addLast("String_Node_Str",new SslHandler(sslEngine));
        }
 catch (        Throwable ex) {
          cl.future().abort(ex);
        }
      }
      pipeline.addLast("String_Node_Str",new HttpClientCodec());
      if (config.isCompressionEnabled()) {
        pipeline.addLast("String_Node_Str",new HttpContentDecompressor());
      }
      IdleStateHandler h=new IdleStateHandler(timer,0,0,config.getIdleConnectionTimeoutInMs(),TimeUnit.MILLISECONDS){
        @Override protected void channelIdle(        ChannelHandlerContext ctx,        IdleState state,        long lastActivityTimeMillis) throws Exception {
          ctx.getChannel().close();
          removeFromCache(ctx);
        }
      }
;
      pipeline.addLast("String_Node_Str",h);
      pipeline.addLast("String_Node_Str",NettyAsyncHttpProvider.this);
      return pipeline;
    }
  }
);
}

Fixed version (ground truth):
void configure(final boolean useSSL,final ConnectListener<?> cl){
  bootstrap.setPipelineFactory(new ChannelPipelineFactory(){
    public ChannelPipeline getPipeline() throws Exception {
      ChannelPipeline pipeline=pipeline();
      if (useSSL) {
        try {
          SSLEngine sslEngine=config.getSSLEngine();
          if (sslEngine == null) {
            sslEngine=SslUtils.getSSLEngine();
          }
          pipeline.addLast("String_Node_Str",new SslHandler(sslEngine));
        }
 catch (        Throwable ex) {
          cl.future().abort(ex);
        }
      }
      pipeline.addLast("String_Node_Str",new HttpClientCodec());
      if (config.isCompressionEnabled()) {
        pipeline.addLast("String_Node_Str",new HttpContentDecompressor());
      }
      IdleStateHandler h=new IdleStateHandler(timer,0,0,config.getIdleConnectionTimeoutInMs(),TimeUnit.MILLISECONDS){
        @Override protected void channelIdle(        ChannelHandlerContext ctx,        IdleState state,        long lastActivityTimeMillis) throws Exception {
          ctx.getChannel().close();
          for (          Entry<String,Channel> e : connectionsPool.entrySet()) {
            if (e.getValue().equals(ctx.getChannel())) {
              connectionsPool.remove(e.getKey());
              return;
            }
          }
        }
      }
;
      pipeline.addLast("String_Node_Str",h);
      pipeline.addLast("String_Node_Str",NettyAsyncHttpProvider.this);
      return pipeline;
    }
  }
);
}
Program: 179
Project: 179
Buggy source:
private Channel lookupInCache(Url url){
  Channel channel=connectionsPool.get(url.getBaseUrl());
  if (channel != null) {
    if (channel.isOpen()) {
      channel.setReadable(true);
    }
 else {
      connectionsPool.remove(url.getBaseUrl());
    }
  }
  return channel;
}

Fixed version (ground truth):
private Channel lookupInCache(Url url){
  Channel channel=connectionsPool.remove(url.getBaseUrl());
  if (channel != null) {
    if (channel.isOpen()) {
      channel.setReadable(true);
    }
 else {
      return null;
    }
  }
  return channel;
}
Program: 180
Project: 180
Buggy source:
public Object call(){
  if (!future.isDone() && !future.isCancelled()) {
    future.abort(new TimeoutException());
    channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(ClosedEvent.class);
    channel.close();
  }
  return null;
}

Fixed version (ground truth):
public Object call(){
  if (!future.isDone() && !future.isCancelled()) {
    future.abort(new TimeoutException());
    channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(ClosedEvent.class);
  }
  return null;
}
Program: 181
Project: 181
Buggy source:
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline=pipeline();
  if (useSSL) {
    try {
      SSLEngine sslEngine=config.getSSLEngine();
      if (sslEngine == null) {
        sslEngine=SslUtils.getSSLEngine();
      }
      pipeline.addLast("String_Node_Str",new SslHandler(sslEngine));
    }
 catch (    Throwable ex) {
      cl.future().abort(ex);
    }
  }
  pipeline.addLast("String_Node_Str",new HttpClientCodec());
  if (config.isCompressionEnabled()) {
    pipeline.addLast("String_Node_Str",new HttpContentDecompressor());
  }
  IdleStateHandler h=new IdleStateHandler(timer,0,0,config.getIdleConnectionTimeoutInMs(),TimeUnit.MILLISECONDS){
    @Override protected void channelIdle(    ChannelHandlerContext ctx,    IdleState state,    long lastActivityTimeMillis) throws Exception {
      ctx.getChannel().close();
      removeFromCache(ctx);
    }
  }
;
  pipeline.addLast("String_Node_Str",h);
  pipeline.addLast("String_Node_Str",NettyAsyncHttpProvider.this);
  return pipeline;
}

Fixed version (ground truth):
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline=pipeline();
  if (useSSL) {
    try {
      SSLEngine sslEngine=config.getSSLEngine();
      if (sslEngine == null) {
        sslEngine=SslUtils.getSSLEngine();
      }
      pipeline.addLast("String_Node_Str",new SslHandler(sslEngine));
    }
 catch (    Throwable ex) {
      cl.future().abort(ex);
    }
  }
  pipeline.addLast("String_Node_Str",new HttpClientCodec());
  if (config.isCompressionEnabled()) {
    pipeline.addLast("String_Node_Str",new HttpContentDecompressor());
  }
  IdleStateHandler h=new IdleStateHandler(timer,0,0,config.getIdleConnectionTimeoutInMs(),TimeUnit.MILLISECONDS){
    @Override protected void channelIdle(    ChannelHandlerContext ctx,    IdleState state,    long lastActivityTimeMillis) throws Exception {
      ctx.getChannel().close();
      for (      Entry<String,Channel> e : connectionsPool.entrySet()) {
        if (e.getValue().equals(ctx.getChannel())) {
          connectionsPool.remove(e.getKey());
          return;
        }
      }
    }
  }
;
  pipeline.addLast("String_Node_Str",h);
  pipeline.addLast("String_Node_Str",NettyAsyncHttpProvider.this);
  return pipeline;
}
Program: 182
Project: 182
Buggy source:
private void finishUpdate(NettyResponseFuture<?> future,ChannelHandlerContext ctx) throws IOException {
  ctx.setAttachment(new DiscardEvent());
  markAsDoneAndCacheConnection(future,ctx.getChannel());
  try {
    ctx.getChannel().setReadable(false);
  }
 catch (  Exception ex) {
    if (log.isTraceEnabled()) {
      log.trace(ex);
    }
  }
}

Fixed version (ground truth):
private void finishUpdate(NettyResponseFuture<?> future,ChannelHandlerContext ctx) throws IOException {
  ctx.setAttachment(new DiscardEvent());
  try {
    ctx.getChannel().setReadable(false);
  }
 catch (  Exception ex) {
    if (log.isTraceEnabled()) {
      log.trace(ex);
    }
  }
  markAsDoneAndCacheConnection(future,ctx.getChannel());
}
Program: 184
Project: 184
Buggy source:
private final static <T>void executeRequest(final Channel channel,final AsyncHttpClientConfig config,final NettyResponseFuture<T> future,final HttpRequest nettyRequest) throws ConnectException {
  if (!channel.isConnected()) {
    String url=channel.getRemoteAddress() != null ? channel.getRemoteAddress().toString() : null;
    if (url == null) {
      try {
        url=future.getUrl().toStringWithoutParams();
      }
 catch (      MalformedURLException e) {
        log.debug(e);
      }
    }
    throw new ConnectException(String.format("String_Node_Str",url));
  }
  channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(future);
  channel.write(nettyRequest);
  try {
    future.setReaperFuture(config.reaper().schedule(new Callable<Object>(){
      public Object call(){
        if (!future.isDone() && !future.isCancelled()) {
          future.abort(new TimeoutException());
          channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(ClosedEvent.class);
          channel.close();
        }
        return null;
      }
    }
,config.getRequestTimeoutInMs(),TimeUnit.MILLISECONDS));
  }
 catch (  RejectedExecutionException ex) {
    future.abort(ex);
  }
}

Fixed version (ground truth):
private final static <T>void executeRequest(final Channel channel,final AsyncHttpClientConfig config,final NettyResponseFuture<T> future,final HttpRequest nettyRequest) throws ConnectException {
  if (!channel.isConnected()) {
    String url=channel.getRemoteAddress() != null ? channel.getRemoteAddress().toString() : null;
    if (url == null) {
      try {
        url=future.getUrl().toStringWithoutParams();
      }
 catch (      MalformedURLException e) {
        log.debug(e);
      }
    }
    throw new ConnectException(String.format("String_Node_Str",url));
  }
  channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(future);
  channel.write(nettyRequest);
  try {
    future.setReaperFuture(config.reaper().schedule(new Callable<Object>(){
      public Object call(){
        if (!future.isDone() && !future.isCancelled()) {
          future.abort(new TimeoutException());
          channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(ClosedEvent.class);
        }
        return null;
      }
    }
,config.getRequestTimeoutInMs(),TimeUnit.MILLISECONDS));
  }
 catch (  RejectedExecutionException ex) {
    future.abort(ex);
  }
}
Program: 185
Project: 185
Buggy source:
/** 
 * {@inheritDoc}
 */
public V get(long l,TimeUnit tu) throws InterruptedException, TimeoutException, ExecutionException {
  if (!isDone() && !isCancelled()) {
    if (!latch.await(l,tu)) {
      isCancelled.set(true);
      TimeoutException te=new TimeoutException("String_Node_Str");
      onThrowable(te);
      throw te;
    }
    if (exEx.get() != null) {
      throw exEx.getAndSet(null);
    }
  }
  return (V)getContent();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
public V get(long l,TimeUnit tu) throws InterruptedException, TimeoutException, ExecutionException {
  if (!isDone() && !isCancelled()) {
    if (!latch.await(l,tu)) {
      isCancelled.set(true);
      TimeoutException te=new TimeoutException("String_Node_Str");
      onThrowable(te);
      throw te;
    }
    isDone.set(true);
    if (exEx.get() != null) {
      throw exEx.getAndSet(null);
    }
  }
  return (V)getContent();
}
Program: 187
Project: 187
Buggy source:
public boolean execute(@NotNull Editor editor,@NotNull final DataContext context,@NotNull ExCommand cmd) throws ExException {
  final String actionName=cmd.getArgument().trim();
  final AnAction action=ActionManager.getInstance().getAction(actionName);
  if (action == null) {
    VimPlugin.showMessage("String_Node_Str" + actionName);
    return false;
  }
  final Application application=ApplicationManager.getApplication();
  if (application.isUnitTestMode()) {
    executeAction(action,context,actionName);
  }
 else {
    application.invokeLater(new Runnable(){
      @Override public void run(){
        executeAction(action,context,actionName);
      }
    }
);
  }
  return true;
}

Fixed version (ground truth):
public boolean execute(@NotNull Editor editor,@NotNull final DataContext context,@NotNull ExCommand cmd) throws ExException {
  final String actionName=cmd.getArgument().trim();
  final AnAction action=ActionManager.getInstance().getAction(actionName);
  if (action == null) {
    VimPlugin.showMessage("String_Node_Str" + actionName);
    return false;
  }
  final Application application=ApplicationManager.getApplication();
  if (application.isUnitTestMode()) {
    executeAction(action,context,actionName);
  }
 else {
    application.invokeLater(new Runnable(){
      @Override public void run(){
        application.invokeLater(new Runnable(){
          @Override public void run(){
            executeAction(action,context,actionName);
          }
        }
);
      }
    }
);
  }
  return true;
}
Program: 189
Project: 189
Buggy source:
private boolean reg_save_equal(@NotNull regsave_T save){
  if (reg_match == null) {
    return reglnum == save.pos.lnum && reginput == regline.ref(save.pos.col);
  }
  return reginput == save.ptr;
}

Fixed version (ground truth):
private boolean reg_save_equal(@NotNull regsave_T save){
  if (reg_match == null) {
    return reglnum == save.pos.lnum && reginput.equals(regline.ref(save.pos.col));
  }
  return reginput.equals(save.ptr);
}
Program: 190
Project: 190
Buggy source:
@Nullable public CharPointer istrchr(char c){
  if (end()) {
    return null;
  }
  int len=seq.length();
  char cc=Character.toUpperCase(c);
  c=Character.toLowerCase(c);
  for (int i=pointer; i < len; i++) {
    char ch=seq.charAt(i);
    if (ch == c || ch == cc) {
      return ref(i - pointer);
    }
  }
  return null;
}

Fixed version (ground truth):
@Nullable public CharPointer istrchr(char c){
  if (end()) {
    return null;
  }
  int len=seq.length();
  char cc=Character.toUpperCase(c);
  c=Character.toLowerCase(c);
  for (int i=pointer; i < len; i++) {
    char ch=seq.charAt(i);
    if (ch == '\0') {
      return null;
    }
    if (ch == c || ch == cc) {
      return ref(i - pointer);
    }
  }
  return null;
}
Program: 191
Project: 191
Buggy source:
@Nullable public CharPointer strchr(char c){
  if (end()) {
    return null;
  }
  int len=seq.length();
  for (int i=pointer; i < len; i++) {
    if (seq.charAt(i) == c) {
      return ref(i - pointer);
    }
  }
  return null;
}

Fixed version (ground truth):
@Nullable public CharPointer strchr(char c){
  if (end()) {
    return null;
  }
  int len=seq.length();
  for (int i=pointer; i < len; i++) {
    char ch=seq.charAt(i);
    if (ch == '\0') {
      return null;
    }
    if (ch == c) {
      return ref(i - pointer);
    }
  }
  return null;
}