Program: 53895
Project: 53895
Buggy source:
/** 
 * Returns the content of an   {@link HttpServletRequest} by decoding it using<code>expectedCharSet</code>, or <code>UTF-8</code> if <code>expectedCharSet</code> is <code>null</null>.
 * @param request the servlet request whose content we want to read
 * @param expectedContentType the expected content (i.e. 'type/subtype' only)in the Content-Type request header, or <code>null</code> if no validation is to be performed, and you are willing to allow for some types of cross type security attacks
 * @param expectedCharSet the expected request charset, or <code>null</code>if no charset validation is to be performed and <code>UTF-8</code> should be assumed
 * @return the content of an {@link HttpServletRequest} by decoding it using<code>expectedCharSet</code>, or <code>UTF-8</code> if <code>expectedCharSet</code> is <code>null</null>
 * @throws IOException if the request's input stream cannot be accessed, readfrom or closed
 * @throws ServletException if the request's content type does notequal the supplied <code>expectedContentType</code> or <code>expectedCharSet</code>
 */
public static String readContent(HttpServletRequest request,String expectedContentType,String expectedCharSet) throws IOException, ServletException {
  if (expectedContentType != null) {
    checkContentTypeIgnoreCase(request,expectedContentType);
  }
  if (expectedCharSet != null) {
    checkCharacterEncodingIgnoreCase(request,expectedCharSet);
  }
  InputStream in=request.getInputStream();
  byte[] buffer=new byte[BUFFER_SIZE];
  ByteArrayOutputStream out=new ByteArrayOutputStream(BUFFER_SIZE);
  try {
    while (true) {
      int byteCount=in.read(buffer);
      if (byteCount == -1) {
        break;
      }
      out.write(buffer,0,byteCount);
    }
    String contentCharSet=expectedCharSet != null ? expectedCharSet : CHARSET_UTF8;
    return out.toString(contentCharSet);
  }
  finally {
    if (in != null) {
      in.close();
    }
  }
}

Fixed version (ground truth):
/** 
 * Returns the content of an   {@link HttpServletRequest} by decoding it using<code>expectedCharSet</code>, or <code>UTF-8</code> if <code>expectedCharSet</code> is <code>null</null>.
 * @param request the servlet request whose content we want to read
 * @param expectedContentType the expected content (i.e. 'type/subtype' only)in the Content-Type request header, or <code>null</code> if no validation is to be performed, and you are willing to allow for some types of cross type security attacks
 * @param expectedCharSet the expected request charset, or <code>null</code>if no charset validation is to be performed and <code>UTF-8</code> should be assumed
 * @return the content of an {@link HttpServletRequest} by decoding it using<code>expectedCharSet</code>, or <code>UTF-8</code> if <code>expectedCharSet</code> is <code>null</code>
 * @throws IOException if the request's input stream cannot be accessed, readfrom or closed
 * @throws ServletException if the request's content type does notequal the supplied <code>expectedContentType</code> or <code>expectedCharSet</code>
 */
public static String readContent(HttpServletRequest request,String expectedContentType,String expectedCharSet) throws IOException, ServletException {
  if (expectedContentType != null) {
    checkContentTypeIgnoreCase(request,expectedContentType);
  }
  if (expectedCharSet != null) {
    checkCharacterEncodingIgnoreCase(request,expectedCharSet);
  }
  InputStream in=request.getInputStream();
  byte[] buffer=new byte[BUFFER_SIZE];
  ByteArrayOutputStream out=new ByteArrayOutputStream(BUFFER_SIZE);
  try {
    while (true) {
      int byteCount=in.read(buffer);
      if (byteCount == -1) {
        break;
      }
      out.write(buffer,0,byteCount);
    }
    String contentCharSet=expectedCharSet != null ? expectedCharSet : CHARSET_UTF8;
    return out.toString(contentCharSet);
  }
  finally {
    if (in != null) {
      in.close();
    }
  }
}