[Demonstration 1]

[Buggy Method]
public PactDslResponse body(DslPart body) {
    for (String matcherName : body.matchers.keySet()) {
        responseMatchers.put("$.body" + matcherName, body.matchers.get(matcherName));
    }
    responseBody = OptionalBody.body(body.toString());
    if (!responseHeaders.containsKey("Content-Type")) {
        responseHeaders.put("Content-Type", ContentType.APPLICATION_JSON.toString());
    }
    return this;
}

[Buggy Hunk]
responseBody = OptionalBody.body(body.toString());

[Patch]
responseBody = OptionalBody.body(body.getBody().toString());

[Demonstration 2]

[Buggy Method]
public void get(URL url, RestResponse response, Map<String, String> requestHeaders) throws IOException, HttpStatusError {
    HttpURLConnection conn;
    try {
        conn = (HttpURLConnection) url.openConnection();
    } catch (ClassCastException e) {
        throw new RuntimeException("Non-HTTP protocols not supported. Got URL: " + url);
    } catch (IOException e) {
        throw check(e);
    }
    // authentication and some settings is static for URLConnection, preserver current setting
    conn.setInstanceFollowRedirects(true);
    configure(conn);
    for (String h : requestHeaders.keySet()) {
        conn.setRequestProperty(h, requestHeaders.get(h));
    }
    logger.info("GET connection to {}", url);
    try {
        conn.connect();
    } catch (IOException e) {
        throw check(e);
    }
    // response should be ok regardless of status, get content
    ResponseHeaders headers = new URLConnectionResponseHeaders(conn);
    int responseCode = conn.getResponseCode();
    // check status code before trying to get response body
    // to avoid the unclassified IOException
    // Currently getting body only for 200 OK.
    // There might be more 2xx responses with a valuable body.
    if (responseCode == HttpURLConnection.HTTP_OK) {
        OutputStream receiver = response.getResponseStream(headers);
        try {
            InputStream body = conn.getInputStream();
            pipe(body, receiver);
            body.close();
        } catch (IOException e) {
            throw check(e);
        } finally {
            conn.disconnect();
        }
    }
    if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP) {
        logger.info("Server responded with redirect ({}): {}", responseCode, headers.get("Location"));
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        try {
            InputStream body = conn.getInputStream();
            if (body == null) {
                logger.warn("Redirect did not contain a body.");
            }
            pipe(body, b);
            body.close();
        } catch (IOException e) {
            throw check(e);
        } finally {
            conn.disconnect();
        }
        throw new HttpStatusError(url.toString(), headers, b.toString());
    } else if (responseCode < 400) {
        // Other non-error responses.
        // Do we need to consume a stream if the server sends one? Important when using keep-alive?
        conn.disconnect();
    } else {
        // Error stream expected for 4xx and 5xx.
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        try {
            InputStream body = conn.getErrorStream();
            if (body == null) {
                throw new RuntimeException("Response error could not be read for status " + conn.getResponseCode());
            }
            pipe(body, b);
            body.close();
        } catch (IOException e) {
            throw check(e);
        } finally {
            conn.disconnect();
        }
        throw new HttpStatusError(url.toString(), headers, b.toString());
    }
}

[Buggy Hunk]
} if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP) {

[Patch]
} else if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP) {

[Demonstration 3]

[Buggy Method]
@Override
@POST
@Path("/relationship/add")
@ApiOperation(value = "Add relationship to concept", notes = "Add relationship to concept on a project branch", response = ValidationResultJpa.class)
public ValidationResult addRelationship(@ApiParam(value = "Project id, e.g. 1", required = true) @QueryParam("projectId") Long projectId, @ApiParam(value = "Concept id, e.g. 2", required = true) @QueryParam("conceptId") Long conceptId, @ApiParam(value = "Concept lastModified, as date", required = true) @QueryParam("lastModified") Long lastModified, @ApiParam(value = "Relationship to add", required = true) ConceptRelationshipJpa relationship, @ApiParam(value = "Override warnings", required = false) @QueryParam("overrideWarnings") boolean overrideWarnings, @ApiParam(value = "Authorization token, e.g. 'author'", required = true) @HeaderParam("Authorization") String authToken) throws Exception {
    Logger.getLogger(getClass()).info("RESTful POST call (MetaEditing): /relationship/" + projectId + "/" + conceptId + "/add for user " + authToken + " with relationship value " + relationship);
    // Prep reusable variables
    final String action = "ADD_RELATIONSHIP";
    final ValidationResult validationResult = new ValidationResultJpa();
    // Instantiate services
    final ContentService contentService = new ContentServiceJpa();
    try {
        // Authorize project role, get userName
        final String userName = authorizeProject(contentService, projectId, securityService, authToken, action, UserRole.AUTHOR);
        // Retrieve the project
        final Project project = contentService.getProject(projectId);
        // Do some standard intialization and precondition checking
        // action and prep services
        final List<Concept> conceptList = initialize(contentService, project, conceptId, relationship.getTo().getId(), userName, action, lastModified, validationResult);
        Concept concept = conceptList.get(0);
        Concept toConcept = conceptList.get(1);
        //
        // Check prerequisites
        //
        // Perform action specific validation - n/a
        // Metadata referential integrity checking
        if (contentService.getRelationshipType(relationship.getRelationshipType(), relationship.getTerminology(), relationship.getVersion()) == null) {
            contentService.rollback();
            throw new LocalException("Cannot add relationship with invalid relationship type - " + relationship.getRelationshipType());
        }
        if (contentService.getAdditionalRelationshipType(relationship.getAdditionalRelationshipType(), relationship.getTerminology(), relationship.getVersion()) == null) {
            contentService.rollback();
            throw new LocalException("Cannot add relationship with invalid additional relationship type - " + relationship.getAdditionalRelationshipType());
        }
        if (contentService.getTerminology(relationship.getTerminology(), relationship.getVersion()) == null) {
            contentService.rollback();
            throw new LocalException("Cannot add relationship with invalid terminology - " + relationship.getTerminology() + ", version: " + relationship.getVersion());
        }
        // Duplicate check
        for (final ConceptRelationship a : concept.getRelationships()) {
            if (a.equals(relationship)) {
                contentService.rollback();
                throw new LocalException("Duplicate relationship - " + relationship.getName());
            }
        }
        // if prerequisites fail, return validation result
        if (!validationResult.getErrors().isEmpty() || (!validationResult.getWarnings().isEmpty() && !overrideWarnings)) {
            // rollback -- unlocks the concept and closes transaction
            contentService.rollback();
            return validationResult;
        }
        //
        // Perform the action (contentService will create atomic actions
        // for CRUD
        // operations)
        //
        relationship.setWorkflowStatus(WorkflowStatus.NEEDS_REVIEW);
        // Assign alternateTerminologyId
        // final IdentifierAssignmentHandler handler = contentService
        // .getIdentifierAssignmentHandler(concept.getTerminology());
        //
        // final String altId = handler.getTerminologyId(relationship);
        // relationship.getAlternateTerminologyIds().put(concept.getTerminology(),
        // altId);
        // set the relationship component last modified
        final ConceptRelationshipJpa newRelationship = (ConceptRelationshipJpa) contentService.addRelationship(relationship);
        // construct inverse relationship
        final ConceptRelationshipJpa inverseRelationship = (ConceptRelationshipJpa) contentService.createInverseConceptRelationship(newRelationship);
        // pass to handler.getTerminologyId
        // final String inverseAltId =
        // handler.getTerminologyId(inverseRelationship);
        // inverseRelationship.getAlternateTerminologyIds()
        // .put(concept.getTerminology(), inverseAltId);
        // set the relationship component last modified
        final ConceptRelationshipJpa newInverseRelationship = (ConceptRelationshipJpa) contentService.addRelationship(inverseRelationship);
        // add the relationship and set the last modified by
        concept.getRelationships().add(newRelationship);
        toConcept.getRelationships().add(newInverseRelationship);
        concept.setWorkflowStatus(WorkflowStatus.NEEDS_REVIEW);
        // update the concept
        contentService.updateConcept(toConcept);
        contentService.updateConcept(concept);
        // log the REST calls
        contentService.addLogEntry(userName, projectId, conceptId, action + " " + newRelationship.getName() + " to concept " + concept.getTerminologyId());
        // commit (also removes the lock)
        contentService.commit();
        // Websocket notification
        final ChangeEvent<ConceptRelationshipJpa> event = new ChangeEventJpa<ConceptRelationshipJpa>(action, authToken, IdType.RELATIONSHIP.toString(), null, newRelationship, concept);
        sendChangeEvent(event);
        return validationResult;
    } catch (Exception e) {
        handleException(e, action);
        return null;
    } finally {
        contentService.close();
        securityService.close();
    }
}

[Buggy Hunk]
action + " " + newRelationship.getName() + " to concept "

[Patch]
action + " " + newRelationship + " to concept "