[Demonstration 1]

[Buggy Method]
@Override
public ServiceAgreementResponse createAgreement(ServiceAgreementRequest offer) throws Exception {
    //transactionID to identify the service request
    String transactionID = UUID.randomUUID().toString();
    //		parse the request to create discovery request
    //always only one serviceRequest in our implementation
    //TODO manage serviceAgreementRequest as List of serviceDefinition
    ServiceDefinition serviceRequest = offer.getServiceDefinitionList().get(0);
    String opType = serviceRequest.getOperationType();
    //Create a new restriction with the same attribute expression and
    //operation scope as in the request.
    Restriction restriction = getRestriction(serviceRequest);
    if (restriction == null) {
        throw new Exception("No restrictions in ServiceAgreementRequest");
    }
    QoSreq qosRequirements = new QoSreq();
    //remove the QoS scopeValues from the operationScopes list, to store them
    //in the QoSreq object
    qosRequirements = getQoSrequirements(restriction.getOperationScope());
    if (qosRequirements == null) {
        throw new Exception("No QoS requirements in ServiceAgreementRequest");
    }
    //		CREATE THE REQUEST FROM THE INFO TAKEN FROM SERVICE_AGREEMENT_REQUEST
    //create list of services
    List<Service> serviceList = createServiceList(serviceRequest.getAttributeList());
    //object to store the details of the service Request
    Request request = new Request(transactionID, opType, qosRequirements, restriction, serviceRequest.getEntityIdList(), serviceList);
    StatusCode statusCode = new StatusCode();
    //		discovery phase
    //get list of equivalentThings
    HashMap<Integer, Thing> thingsMap = discoverThings(request, statusCode, true);
    if (thingsMap == null) {
        ServiceAgreementResponse response = new ServiceAgreementResponse();
        response.setServiceID(null);
        response.setErrorCode(statusCode);
        return response;
    }
    //TODO String offer = qosManager.getTemplate();
    //TODO prepare offer
    //TODO store Pair<TransactionID, <EquivalentThings, SeviceRequest>>
    //		qosManager.createAgreement(offer);
    logger.info("############## createAgreement ###############");
    ServiceAgreementResponse response = new ServiceAgreementResponse();
    response.setServiceID("home_service");
    StatusCode statusCodeEx = new StatusCode(Code.OK_200.getCode(), ReasonPhrase.OK_200.toString(), "Succes Operation");
    response.setErrorCode(statusCode);
    return response;
}

[Buggy Hunk]
HashMap<Integer, Thing> thingsMap = discoverThings(request, statusCode, true);

[Patch]
HashMap<Integer, Thing> thingsMap = discoverThings(request, statusCode);

[Demonstration 2]

[Buggy Method]
@Override
public void run() {
    try {
        // try to export remote object on available port
        boolean exported = false;
        INameserver thisExported = null;
        for (int i = 0; i < 7 && !exported; i++) {
            try {
                thisExported = (INameserver) UnicastRemoteObject.exportObject(this, registryPort - i);
                exported = true;
            } catch (ExportException ee) {
                // when port is already in use
            }
        }
        if (!exported) {
            System.out.println("There was no port available between " + (registryPort - 6) + " and " + registryPort + " to start the nameserver on");
            return;
        }
        // start registry if root ns
        if (managedDomain == null) {
            registry = LocateRegistry.createRegistry(registryPort);
            registry.bind(rootId, thisExported);
            System.out.println("Nameserver 'root-nameserver' started");
        } else {
            registry = LocateRegistry.getRegistry(registryHost, registryPort);
            INameserver rootNs = (INameserver) registry.lookup(rootId);
            rootNs.registerNameserver(managedDomain, thisExported, thisExported);
            System.out.println("Nameserver '" + managedDomain + "' started");
        }
        // initialize shell
        shell = new Shell(componentName, userRequestStream, userResponseStream);
        shell.register(this);
        new Thread(shell).start();
    } catch (Exception e) {
        System.out.println("Nameserver could not start: " + e.getLocalizedMessage());
        try {
            exit();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

[Buggy Hunk]
System.out.println("Nameserver could not start: " + e.getLocalizedMessage());

[Patch]
System.out.println("Nameserver could not start. Was the root nameserver started? (" + e.getLocalizedMessage() + ")");

[Demonstration 3]

[Buggy Method]
public static void main(String[] args) throws SQLException {
    Connection conn = DriverManager.getConnection("jdbc:h2:./main");
    () -> {
    }.start();
    Statement stmt = conn.createStatement();
    stmt.execute("CREATE TABLE id IDENTITY, username VARCHAR, address VARCHAR, email VARCHAR");
}

[Buggy Hunk]
().start();

[Patch]
Server.createWebServer().start();