Program: 107707
Project: 107707
Buggy source:
@Override public boolean respond(Request request) throws IOException {
  boolean block=false;
  String reqHost=null;
  String refHost=null;
  try {
    reqHost=(new URL(request.url)).getHost();
    refHost=(new URL(request.getRequestHeader("String_Node_Str"))).getHost();
  }
 catch (  MalformedURLException e) {
  }
  try {
    block=application.matches(request.url,request.query,reqHost,refHost,request.getRequestHeader("String_Node_Str"));
  }
 catch (  Exception e) {
    Log.e(prefix,"String_Node_Str",e);
  }
  request.log(Server.LOG_LOG,prefix,block + "String_Node_Str" + request.url);
  if (block) {
    request.sendError(403,"String_Node_Str");
    return true;
  }
  if (request.url.startsWith("String_Node_Str") == false && request.url.startsWith("String_Node_Str") == false) {
    return false;
  }
  String url=request.url;
  if ((request.query != null) && (request.query.length() > 0)) {
    url+="String_Node_Str" + request.query;
  }
  int count=request.server.requestCount;
  if (shouldLog) {
    System.err.println(dumpHeaders(count,request,request.headers,true));
  }
  String pc=request.headers.get("String_Node_Str");
  if (pc != null) {
    request.connectionHeader="String_Node_Str";
    request.keepAlive=pc.equalsIgnoreCase("String_Node_Str");
  }
  HttpRequest.removePointToPointHeaders(request.headers,false);
  HttpRequest target=new HttpRequest(url);
  try {
    target.setMethod(request.method);
    request.headers.copyTo(target.requestHeaders);
    if (proxyHost != null) {
      target.setProxy(proxyHost,proxyPort);
      if (auth != null) {
        target.requestHeaders.add("String_Node_Str",auth);
      }
    }
    if (request.postData != null) {
      OutputStream out=target.getOutputStream();
      out.write(request.postData);
      out.close();
    }
    target.connect();
    if (shouldLog) {
      System.err.println("String_Node_Str" + target.status + "String_Node_Str"+ dumpHeaders(count,request,target.responseHeaders,false));
    }
    HttpRequest.removePointToPointHeaders(target.responseHeaders,true);
    target.responseHeaders.copyTo(request.responseHeaders);
    try {
      request.responseHeaders.add("String_Node_Str",target.status.substring(0,8) + via);
    }
 catch (    StringIndexOutOfBoundsException e) {
      request.responseHeaders.add("String_Node_Str",via);
    }
    String type=request.responseHeaders.get("String_Node_Str");
    String selectors=null;
    if (type != null && type.toLowerCase().startsWith("String_Node_Str")) {
      selectors=application.getSelectorsForDomain(reqHost);
    }
    if (selectors == null || target.getResponseCode() != 200) {
      int contentLength=target.getContentLength();
      if (contentLength == 0) {
        request.sendHeaders(-1,null,-1);
      }
 else {
        request.sendResponse(target.getInputStream(),contentLength,null,target.getResponseCode());
      }
    }
 else {
      HttpInputStream his=target.getInputStream();
      int size=target.getContentLength();
      if (size < 0) {
        size=Integer.MAX_VALUE;
      }
      FilterInputStream in=null;
      FilterOutputStream out=null;
      String encodingHeader=request.responseHeaders.get("String_Node_Str");
      if (encodingHeader != null) {
        encodingHeader=encodingHeader.toLowerCase();
        if (encodingHeader.equals("String_Node_Str") || encodingHeader.equals("String_Node_Str")) {
          in=new GZIPInputStream(his);
          request.responseHeaders.remove("String_Node_Str");
          request.responseHeaders.remove("String_Node_Str");
          out=new ChunkedOutputStream(request.out);
          request.responseHeaders.add("String_Node_Str","String_Node_Str");
          size=Integer.MAX_VALUE;
        }
 else         if (encodingHeader.equals("String_Node_Str") || encodingHeader.equals("String_Node_Str")) {
          in=new InflaterInputStream(his);
          request.responseHeaders.remove("String_Node_Str");
          request.responseHeaders.remove("String_Node_Str");
          out=new ChunkedOutputStream(request.out);
          request.responseHeaders.add("String_Node_Str","String_Node_Str");
          size=Integer.MAX_VALUE;
        }
 else {
          in=new BufferedInputStream(his);
          out=request.out;
          selectors=null;
        }
      }
      request.sendHeaders(-1,null,-1);
      byte[] buf=new byte[Math.min(4096,size)];
      Log.e(prefix,request.url);
      boolean sent=selectors == null;
      BoyerMoore matcher=new BoyerMoore("String_Node_Str".getBytes());
      while (size > 0) {
        out.flush();
        count=in.read(buf,0,Math.min(buf.length,size));
        if (count < 0) {
          break;
        }
        size-=count;
        try {
          if (!sent && count > 0) {
            List<Integer> matches=matcher.match(buf,0,count);
            if (!matches.isEmpty()) {
              byte[] addon=selectors.getBytes();
              int m=matches.get(0);
              out.write(buf,0,m);
              out.write(addon);
              out.write(buf,m,count - m);
              sent=true;
              continue;
            }
          }
          out.write(buf,0,count);
        }
 catch (        IOException e) {
          break;
        }
      }
      try {
        ((ChunkedOutputStream)out).writeFinalChunk();
      }
 catch (      ClassCastException e) {
      }
    }
  }
 catch (  InterruptedIOException e) {
    request.sendError(408,"String_Node_Str");
  }
catch (  EOFException e) {
    request.sendError(500,"String_Node_Str");
  }
catch (  UnknownHostException e) {
    request.sendError(500,"String_Node_Str");
  }
catch (  ConnectException e) {
    request.sendError(500,"String_Node_Str");
  }
catch (  IOException e) {
    String msg="String_Node_Str";
    if (e.getMessage() != null) {
      msg+="String_Node_Str" + e.getMessage();
    }
    request.sendError(500,msg);
    Log.e(prefix,msg,e);
  }
 finally {
    target.close();
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean respond(Request request) throws IOException {
  boolean block=false;
  String reqHost=null;
  String refHost=null;
  try {
    reqHost=(new URL(request.url)).getHost();
    refHost=(new URL(request.getRequestHeader("String_Node_Str"))).getHost();
  }
 catch (  MalformedURLException e) {
  }
  try {
    block=application.matches(request.url,request.query,reqHost,refHost,request.getRequestHeader("String_Node_Str"));
  }
 catch (  Exception e) {
    Log.e(prefix,"String_Node_Str",e);
  }
  request.log(Server.LOG_LOG,prefix,block + "String_Node_Str" + request.url);
  if (block) {
    request.sendError(403,"String_Node_Str");
    return true;
  }
  if (request.url.startsWith("String_Node_Str") == false && request.url.startsWith("String_Node_Str") == false) {
    return false;
  }
  String url=request.url;
  if ((request.query != null) && (request.query.length() > 0)) {
    url+="String_Node_Str" + request.query;
  }
  int count=request.server.requestCount;
  if (shouldLog) {
    System.err.println(dumpHeaders(count,request,request.headers,true));
  }
  String pc=request.headers.get("String_Node_Str");
  if (pc != null) {
    request.connectionHeader="String_Node_Str";
    request.keepAlive=pc.equalsIgnoreCase("String_Node_Str");
  }
  HttpRequest.removePointToPointHeaders(request.headers,false);
  HttpRequest target=new HttpRequest(url);
  try {
    target.setMethod(request.method);
    request.headers.copyTo(target.requestHeaders);
    if (proxyHost != null) {
      target.setProxy(proxyHost,proxyPort);
      if (auth != null) {
        target.requestHeaders.add("String_Node_Str",auth);
      }
    }
    if (request.postData != null) {
      OutputStream out=target.getOutputStream();
      out.write(request.postData);
      out.close();
    }
    target.connect();
    if (shouldLog) {
      System.err.println("String_Node_Str" + target.status + "String_Node_Str"+ dumpHeaders(count,request,target.responseHeaders,false));
    }
    HttpRequest.removePointToPointHeaders(target.responseHeaders,true);
    target.responseHeaders.copyTo(request.responseHeaders);
    try {
      request.responseHeaders.add("String_Node_Str",target.status.substring(0,8) + via);
    }
 catch (    StringIndexOutOfBoundsException e) {
      request.responseHeaders.add("String_Node_Str",via);
    }
    String type=request.responseHeaders.get("String_Node_Str");
    String selectors=null;
    if (type != null && type.toLowerCase().startsWith("String_Node_Str")) {
      selectors=application.getSelectorsForDomain(reqHost);
    }
    if (selectors == null || target.getResponseCode() != 200) {
      int contentLength=target.getContentLength();
      if (contentLength == 0) {
        request.sendHeaders(-1,null,-1);
      }
 else {
        request.sendResponse(target.getInputStream(),contentLength,null,target.getResponseCode());
      }
    }
 else {
      HttpInputStream his=target.getInputStream();
      int size=target.getContentLength();
      if (size < 0) {
        size=Integer.MAX_VALUE;
      }
      FilterInputStream in=null;
      FilterOutputStream out=null;
      String encodingHeader=request.responseHeaders.get("String_Node_Str");
      if (encodingHeader != null) {
        encodingHeader=encodingHeader.toLowerCase();
        if (encodingHeader.equals("String_Node_Str") || encodingHeader.equals("String_Node_Str")) {
          in=new GZIPInputStream(his);
        }
 else         if (encodingHeader.equals("String_Node_Str") || encodingHeader.equals("String_Node_Str")) {
          in=new InflaterInputStream(his);
        }
 else {
          in=new BufferedInputStream(his);
          out=request.out;
          selectors=null;
        }
      }
 else {
        in=new BufferedInputStream(his);
      }
      if (out == null) {
        request.responseHeaders.remove("String_Node_Str");
        request.responseHeaders.remove("String_Node_Str");
        out=new ChunkedOutputStream(request.out);
        request.responseHeaders.add("String_Node_Str","String_Node_Str");
        size=Integer.MAX_VALUE;
      }
      request.sendHeaders(-1,null,-1);
      byte[] buf=new byte[Math.min(4096,size)];
      Log.e(prefix,request.url);
      boolean sent=selectors == null;
      BoyerMoore matcher=new BoyerMoore("String_Node_Str".getBytes());
      while (size > 0) {
        out.flush();
        count=in.read(buf,0,Math.min(buf.length,size));
        if (count < 0) {
          break;
        }
        size-=count;
        try {
          if (!sent && count > 0) {
            List<Integer> matches=matcher.match(buf,0,count);
            if (!matches.isEmpty()) {
              byte[] addon=selectors.getBytes();
              int m=matches.get(0);
              out.write(buf,0,m);
              out.write(addon);
              out.write(buf,m,count - m);
              sent=true;
              continue;
            }
          }
          out.write(buf,0,count);
        }
 catch (        IOException e) {
          break;
        }
      }
      try {
        ((ChunkedOutputStream)out).writeFinalChunk();
      }
 catch (      ClassCastException e) {
      }
    }
  }
 catch (  InterruptedIOException e) {
    request.sendError(408,"String_Node_Str");
  }
catch (  EOFException e) {
    request.sendError(500,"String_Node_Str");
  }
catch (  UnknownHostException e) {
    request.sendError(500,"String_Node_Str");
  }
catch (  ConnectException e) {
    request.sendError(500,"String_Node_Str");
  }
catch (  IOException e) {
    String msg="String_Node_Str";
    if (e.getMessage() != null) {
      msg+="String_Node_Str" + e.getMessage();
    }
    request.sendError(500,msg);
    Log.e(prefix,msg,e);
  }
 finally {
    target.close();
  }
  return true;
}