[Demonstration 1]

[Buggy Method]
@Override
public AioConnection aioConnect(Action action, Gateway gateway, AioClient client) throws IOException {
    AioConnection connection = (AioConnection) action.getExtra().get(AioConnection.class);
    if (connection != null) {
        return connection;
    }
    for (Connector connector : connectors.values()) {
        if (connector.supports(action) && connector instanceof AioConnection) {
            AioConnector aioConnector = (AioConnector) connector;
            connection = aioConnector.aioConnect(action, gateway, this);
            action.getExtra().put(AioConnection.class, connection);
            return connection;
        }
    }
    throw new IOException("unsupported protocol " + action.getProtocol());
}

[Buggy Hunk]
if (connector.supports(action) && connector instanceof AioConnection) {

[Patch]
if (connector.supports(action) && connector instanceof AioConnector) {

[Demonstration 2]

[Buggy Method]
private static Path relativize(Path parent, Path child, FileSystem targetFs) {
    if (parent.equals(child)) {
        return targetFs.getPath("");
    }
    String parentString = parent.toString();
    String childString = child.toString();
    if (parentString.endsWith("/")) {
        parentString = parentString.substring(0, parentString.length() - 1);
    }
    if (childString.endsWith("/")) {
        childString = childString.substring(0, childString.length() - 1);
    }
    parent = parent.getFileSystem().getPath(parentString);
    child = child.getFileSystem().getPath(childString);
    Path relative = parent.relativize(child);
    String root = relative.getName(0).toString();
    String[] components = new String[relative.getNameCount() - 1];
    for (int i = 0; i < components.length; i++) {
        components[i] = relative.getName(i + 1).toString();
    }
    return targetFs.getPath(root, components);
}

[Buggy Hunk]
if (parentString.endsWith("/")) {

[Patch]
if (parentString.endsWith("/") && !parentString.equals("/")) {

[Demonstration 3]

[Buggy Method]
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createFromArtifact(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body, @FormDataParam("artifactType") QName artifactType, @FormDataParam("nodeTypes") Set<QName> nodeTypes, @FormDataParam("infrastructureNodeType") QName infrastructureNodeType, @FormDataParam("tags") Set<String> sentTags, @Context UriInfo uriInfo) throws IllegalArgumentException, JAXBException, IOException {
    Set<String> tags = Utils.clean(sentTags);
    nodeTypes = Utils.cleanQNameSet(nodeTypes);
    Collection<ServiceTemplateId> xaasPackages = this.getXaaSPackageTemplates(artifactType);
    Collection<ServiceTemplateId> toRemove = new ArrayList<ServiceTemplateId>();
    // check whether the serviceTemplate contains all the given nodeTypes
    for (ServiceTemplateId serviceTemplate : xaasPackages) {
        if (!Utils.containsNodeTypes(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), nodeTypes) | !Utils.containsTags(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), tags)) {
            toRemove.add(serviceTemplate);
            continue;
        }
        if (infrastructureNodeType != null) {
            if (Utils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageInfrastructure") == null) {
                toRemove.add(serviceTemplate);
                continue;
            } else {
                String value = Utils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageInfrastructure");
                String localName = value.split("}")[1];
                String namespace = value.split("}")[0].substring(1);
                if (!infrastructureNodeType.equals(new QName(namespace, localName))) {
                    toRemove.add(serviceTemplate);
                }
            }
        }
    }
    xaasPackages.removeAll(toRemove);
    if (xaasPackages.size() <= 0) {
        return Response.serverError().entity("No suitable ServiceTemplate found for given artifact and configuration").build();
    }
    // take the first found serviceTemplate
    ServiceTemplateId serviceTemplate = xaasPackages.iterator().next();
    // create new name for the cloned sTemplate
    String newTemplateName = fileDetail.getFileName() + "ServiceTemplate";
    // create artifactTemplate for the uploaded artifact
    ArtifactTemplateId artifactTemplateId = Utils.createArtifactTemplate(uploadedInputStream, fileDetail, body, artifactType, uriInfo);
    // clone serviceTemplate
    ServiceTemplateId serviceTemplateId = Utils.cloneServiceTemplate(serviceTemplate, newTemplateName, fileDetail.getFileName());
    if (Utils.hasDA(serviceTemplateId, Utils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageNode"), Utils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageDeploymentArtifact"))) {
        // inject artifact as DA into cloned ServiceTemplate
        Utils.injectArtifactTemplateIntoDeploymentArtifact(serviceTemplateId, Utils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageNode"), Utils.getTagValue(new ServiceTemplateResource(serviceTemplate).getServiceTemplate(), "xaasPackageDeploymentArtifact"), artifactTemplateId);
    } else {
        return Response.serverError().entity("Tagged DeploymentArtifact couldn't be found on given specified NodeTemplate").build();
    }
    URI absUri = Utils.getAbsoluteURI(serviceTemplateId);
    // http://localhost:8080/winery/servicetemplates/winery/servicetemplates/http%253A%252F%252Fopentosca.org%252Fservicetemplates/hs_err_pid13228.logServiceTemplate/
    // http://localhost:8080/winery/servicetemplates/winery/servicetemplates/http%253A%252F%252Fopentosca.org%252Fservicetemplates/java0.logServiceTemplate/
    String absUriString = absUri.toString().replace("/winery/servicetemplates", "");
    absUri = URI.create(absUriString);
    return Response.created(absUri).build();
}

[Buggy Hunk]
if (infrastructureNodeType != null) {

[Patch]
if (infrastructureNodeType != null && !infrastructureNodeType.getLocalPart().equals("undefined")) {