Program: 17822
Project: 17822
Buggy source:
private BatchPart parseMultipart(final Scanner scanner,final String boundary,final boolean isChangeSet) throws BatchException {
  Map<String,String> mimeHeaders=new HashMap<String,String>();
  BatchPart multipart=null;
  List<ODataRequest> requests=new ArrayList<ODataRequest>();
  if (scanner.hasNext("String_Node_Str" + boundary + REG_EX_ZERO_OR_MORE_WHITESPACES)) {
    scanner.next();
    currentLineNumber++;
    mimeHeaders=parseHeaders(scanner);
    currentMimeHeaderContentId=mimeHeaders.get(BatchConstants.HTTP_CONTENT_ID.toLowerCase());
    String contentType=mimeHeaders.get(HttpHeaders.CONTENT_TYPE.toLowerCase());
    if (contentType == null) {
      throw new BatchException(BatchException.MISSING_CONTENT_TYPE);
    }
    if (isChangeSet) {
      if (BatchConstants.HTTP_APPLICATION_HTTP.equalsIgnoreCase(contentType)) {
        validateEncoding(mimeHeaders.get(BatchConstants.HTTP_CONTENT_TRANSFER_ENCODING.toLowerCase()));
        parseNewLine(scanner);
        requests.add(parseRequest(scanner,isChangeSet));
        multipart=new BatchPartImpl(false,requests);
      }
 else {
        throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(BatchConstants.HTTP_APPLICATION_HTTP));
      }
    }
 else {
      if (BatchConstants.HTTP_APPLICATION_HTTP.equalsIgnoreCase(contentType)) {
        validateEncoding(mimeHeaders.get(BatchConstants.HTTP_CONTENT_TRANSFER_ENCODING.toLowerCase()));
        parseNewLine(scanner);
        requests.add(parseRequest(scanner,isChangeSet));
        multipart=new BatchPartImpl(false,requests);
      }
 else       if (contentType.matches(REG_EX_OPTIONAL_WHITESPACE + BatchConstants.MULTIPART_MIXED + ANY_CHARACTERS)) {
        String changeSetBoundary=getBoundary(contentType);
        if (boundary.equals(changeSetBoundary)) {
          throw new BatchException(BatchException.INVALID_CHANGESET_BOUNDARY.addContent(currentLineNumber));
        }
        List<ODataRequest> changeSetRequests=new LinkedList<ODataRequest>();
        parseNewLine(scanner);
        Pattern changeSetCloseDelimiter=Pattern.compile("String_Node_Str" + changeSetBoundary + "String_Node_Str"+ REG_EX_ZERO_OR_MORE_WHITESPACES);
        while (!scanner.hasNext(changeSetCloseDelimiter)) {
          BatchPart part=parseMultipart(scanner,changeSetBoundary,true);
          if (part.getRequests().size() == 1) {
            changeSetRequests.add(part.getRequests().get(0));
          }
        }
        scanner.next(changeSetCloseDelimiter);
        currentLineNumber++;
        multipart=new BatchPartImpl(true,changeSetRequests);
      }
 else {
        throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(BatchConstants.MULTIPART_MIXED + "String_Node_Str" + BatchConstants.HTTP_APPLICATION_HTTP));
      }
    }
  }
 else   if (scanner.hasNext(boundary + REG_EX_ZERO_OR_MORE_WHITESPACES)) {
    currentLineNumber++;
    throw new BatchException(BatchException.INVALID_BOUNDARY_DELIMITER.addContent(currentLineNumber));
  }
 else   if (scanner.hasNext(REG_EX_ANY_BOUNDARY_STRING)) {
    currentLineNumber++;
    throw new BatchException(BatchException.NO_MATCH_WITH_BOUNDARY_STRING.addContent(boundary).addContent(currentLineNumber));
  }
 else {
    currentLineNumber++;
    throw new BatchException(BatchException.MISSING_BOUNDARY_DELIMITER.addContent(currentLineNumber));
  }
  return multipart;
}

Fixed version (ground truth):
private BatchPart parseMultipart(final Scanner scanner,final String boundary,final boolean isChangeSet) throws BatchException {
  Map<String,String> mimeHeaders=new HashMap<String,String>();
  BatchPart multipart=null;
  List<ODataRequest> requests=new ArrayList<ODataRequest>();
  if (scanner.hasNext("String_Node_Str" + boundary + REG_EX_ZERO_OR_MORE_WHITESPACES)) {
    scanner.next();
    currentLineNumber++;
    mimeHeaders=parseHeaders(scanner);
    currentMimeHeaderContentId=mimeHeaders.get(BatchConstants.HTTP_CONTENT_ID.toLowerCase(Locale.ENGLISH));
    String contentType=mimeHeaders.get(HttpHeaders.CONTENT_TYPE.toLowerCase(Locale.ENGLISH));
    if (contentType == null) {
      throw new BatchException(BatchException.MISSING_CONTENT_TYPE);
    }
    if (isChangeSet) {
      if (BatchConstants.HTTP_APPLICATION_HTTP.equalsIgnoreCase(contentType)) {
        validateEncoding(mimeHeaders.get(BatchConstants.HTTP_CONTENT_TRANSFER_ENCODING.toLowerCase(Locale.ENGLISH)));
        parseNewLine(scanner);
        requests.add(parseRequest(scanner,isChangeSet));
        multipart=new BatchPartImpl(false,requests);
      }
 else {
        throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(BatchConstants.HTTP_APPLICATION_HTTP));
      }
    }
 else {
      if (BatchConstants.HTTP_APPLICATION_HTTP.equalsIgnoreCase(contentType)) {
        validateEncoding(mimeHeaders.get(BatchConstants.HTTP_CONTENT_TRANSFER_ENCODING.toLowerCase(Locale.ENGLISH)));
        parseNewLine(scanner);
        requests.add(parseRequest(scanner,isChangeSet));
        multipart=new BatchPartImpl(false,requests);
      }
 else       if (contentType.matches(REG_EX_OPTIONAL_WHITESPACE + BatchConstants.MULTIPART_MIXED + ANY_CHARACTERS)) {
        String changeSetBoundary=getBoundary(contentType);
        if (boundary.equals(changeSetBoundary)) {
          throw new BatchException(BatchException.INVALID_CHANGESET_BOUNDARY.addContent(currentLineNumber));
        }
        List<ODataRequest> changeSetRequests=new LinkedList<ODataRequest>();
        parseNewLine(scanner);
        Pattern changeSetCloseDelimiter=Pattern.compile("String_Node_Str" + changeSetBoundary + "String_Node_Str"+ REG_EX_ZERO_OR_MORE_WHITESPACES);
        while (!scanner.hasNext(changeSetCloseDelimiter)) {
          BatchPart part=parseMultipart(scanner,changeSetBoundary,true);
          if (part.getRequests().size() == 1) {
            changeSetRequests.add(part.getRequests().get(0));
          }
        }
        scanner.next(changeSetCloseDelimiter);
        currentLineNumber++;
        multipart=new BatchPartImpl(true,changeSetRequests);
      }
 else {
        throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(BatchConstants.MULTIPART_MIXED + "String_Node_Str" + BatchConstants.HTTP_APPLICATION_HTTP));
      }
    }
  }
 else   if (scanner.hasNext(boundary + REG_EX_ZERO_OR_MORE_WHITESPACES)) {
    currentLineNumber++;
    throw new BatchException(BatchException.INVALID_BOUNDARY_DELIMITER.addContent(currentLineNumber));
  }
 else   if (scanner.hasNext(REG_EX_ANY_BOUNDARY_STRING)) {
    currentLineNumber++;
    throw new BatchException(BatchException.NO_MATCH_WITH_BOUNDARY_STRING.addContent(boundary).addContent(currentLineNumber));
  }
 else {
    currentLineNumber++;
    throw new BatchException(BatchException.MISSING_BOUNDARY_DELIMITER.addContent(currentLineNumber));
  }
  return multipart;
}